I am analyzing a WPF application that basically retrieves data from a server and displays data in a graphical interface.
This code is not mine, and the application has a problem related to the slow response from the GUI, I am trying to find the cause of this problem.
I want to share with you my idea of โโwhat might be the problem, and I would like to hear what you think about it, regardless of whether it makes sense or not.
To get data from the server, the application uses 7 threads (this is mainly due to the logic of the application, so do not pay too much attention to why 7, and not just one ...), now each thread is created by calling a method called CreateThreadForTask ()
public void StartAllThreads()
{
this.CreateThreadForTask(Tasks.Task1);
this.CreateThreadForTask(Tasks.Task2);
this.CreateThreadForTask(Tasks.Task3);
this.CreateThreadForTask(Tasks.Task4);
this.CreateThreadForTask(Tasks.Task5);
this.CreateThreadForTask(Tasks.Task6);
this.CreateThreadForTask(Tasks.Task7);
}
public void CreateThreadForTask(Tasks task)
{
...
timer = null;
timer = new DispatcherTimer();
timer.Tick += new EventHandler(RunMainSyncForTask);
timer.Start();
}
public void RunMainSyncForTask(object s, EventArgs e)
{
int sec = int.Parse(AppSettings.GetSetting("syncInterval"));
timer.Interval = new TimeSpan(0, 0, sec);
threadCaller = InitializeThread();
threadCaller.DoWork += DoWorkEventHandler(StartSync);
threadCaller.RunWorkerAsync();
}
, , DispatcherTimer; , 7 DispatcherTimer Tick RunMainSyncForTask(), , .
MSDN
DispatcherTimer .
, , , . , DispatcherTimer , . DispatcherTimer .
, , , , 7 ; - DispatcherTimer , GUI - , .
, , 90-95% , , , .
, , .
.