好吧,據我從線程讀取這是不可能的,但在我的情況下肯定會發生。非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