好吧,据我从线程读取这是不可能的,但在我的情况下肯定会发生。非ui线程可以阻塞ui线程吗?导致它冻结并变得无法响应?
根据多少后台任务我也开始肯定影响我的GUI响应,即使他们有0相对于UI线程
所以我的问题是不要任何人有任何想法如何其他线程可以使用户界面变得反应迟钝?
我100%确定这些非ui线程导致其缓慢,因为它甚至在我禁用所有gui更新事件时发生。它肯定由多少个线程在我的情况(上抓取网址任务和处理这些抓取网页的任务),我开始
这里实现我的UI线程,我如何启动后台任务:
InitializeComponent();
this.DataContext = this;
ThreadPool.SetMaxThreads(10000, 10000);
ThreadPool.SetMinThreads(10000, 10000);
PublicVariables.initPublicVariables();
PublicStaticFunctions.func_initLists();
PublicSettings.func_init_Settings_Messages();
Task.Factory.StartNew(() =>
{
CheckCrawlURLs.func_StartCrawlingWaitingUrls();
AddUrlsToDB.func_StartUrlAddProcess();
LoadCrawlingUrlsFromDatabase.func_StartLoadingUrlsFromDB();
GlobalStats.startUpdatingGlobalStatValues();
PagesProcessor.func_StartProcessingWaitingPages();
}, CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
AppDomain currentDomain = AppDomain.CurrentDomain;
Application.Current.DispatcherUnhandledException +=
new DispatcherUnhandledExceptionEventHandler(CloseCrashHandlers.AppDispatcherUnhandledException);
currentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CloseCrashHandlers.CrashCloseHandler);
Closing += new CancelEventHandler(CloseCrashHandlers.CloseHander);
set_Buttons_Status();
_timer = new Timer(updateGlobalStatistics,
null,
PublicSettings.irTimers_Delayed_Start_MiliSeconds,
PublicSettings.ir_RefreshUI_MS);
WebConnectionStats.Init();
只是不要使用太多的线程。 [这个答案](http://stackoverflow.com/a/2044198/1136211)可能会有所帮助。 – Clemens 2015-01-15 17:04:31
@Clemens是的,可以解决问题,但我想知道一些事情。我有很多的CPU功率,内存和硬盘的速度。所以我希望我的软件能吸收所有的资源,但它肯定会杀死用户界面。应用程序工作正常。 – MonsterMMORPG 2015-01-15 17:06:04