【发布时间】:2015-01-16 07:56:01
【问题描述】:
好吧,据我从这里的线程中读取,这是不可能的,但在我的情况下肯定会发生。
根据我启动的后台任务的数量,肯定会影响我的 gui 响应能力,即使它们与 ui 线程的关系为 0
所以我的问题是有人知道其他线程如何使 ui 变得无响应吗?
我 100% 确定这些非 ui 线程会导致其运行缓慢,因为即使我禁用所有 gui 更新事件也会发生这种情况。在我的情况下,它肯定会受到多少线程的影响(抓取 urls 任务和处理这些抓取的页面任务)我开始
这是我的 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();
【问题讨论】:
-
只是不要使用太多线程。 This answer 可能会有所帮助。
-
@Clemens 是的,可以解决问题,但我想知道一些事情。我有充足的 CPU 功率、内存和硬盘驱动器速度。所以我希望我的软件吸走我所有的资源,但它肯定会杀死用户界面。应用程序工作正常。
标签: c# wpf multithreading task-parallel-library windows-8.1