Reputation: 23840
Alright as far as I read from threads here it is not possible but in my case definitely happening.
Depending on how many background tasks I do start definitely effects my gui responsiveness even though they have 0 relation to ui thread
So my question is do anybody have any idea how other threads can make ui become unresponsive ?
I am 100% sure that these non ui threads causing its slowness because it happens even when i disable all gui update events. And it definitely effected by how many threads in my case (crawling urls tasks and processing these crawled pages tasks) I start
Here is my ui thread and how I start background tasks:
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();
Upvotes: 0
Views: 563
Reputation: 203828
Your machine can't run an infinite number of threads all at the same time. It can only ever actually run a few at once. It then needs to rotate through the various threads, giving them each a small chunk of time, in order to "fake" parallelization to a greater degree.
The more threads you have, the smaller piece of the pie each one gets. If you have enough threads you end up getting "starvation", where each thread gets so little time that it can't do anything productive, and the whole machine just crawls to a halt. This is exacerbated by the fact that there is a cost to switching threads; a machine can get to the point where it ends up spending most all of its time just switching between threads, rather than doing productive work.
To prevent this you should limit the number of threads you create to a fairly small number. If you rely on the thread pool, its scheduler will generally be effective at not creating more threads than would be efficient on your machine.
Upvotes: 7
Reputation: 26298
One of the techiques here is to actually separate UI and long running stuff into separate processes, so they don't interfere.
It's quite possible that the garbage collector is pausing all the threads to do cleaning of heap, thus you experience a lag.
You could also try to use different GC modes, such as concurrent, background.. and see how they affect the performance.
It might be also possible to raise the priority of UI thread, and lower the priority of other worker threads, though it's a bit unclear why you have so many threads at all.
http://msdn.microsoft.com/en-us/library/0xy59wtx%28v=vs.110%29.aspx
Upvotes: 1
Reputation: 100547
UI responsiveness is heavily impacted by overall machine load. Pushing CPU/memory usage toward 100% will pretty much guarantee slowness of UI.
How can you do that:
Upvotes: 1