There are three threads in my application, for example:
private Thread _analysisThread; private Thread _head2HeadThread; private Thread _formThread;
and each thread starts as follows:
if (_analysisThread == null || !_analysisThread.IsAlive) { _analysisThread = new Thread(() => { Analysis.Logic(match); }); _analysisThread.Start(); }
I have a ListView where the user can select an item and then start the stream again, but I want this to not make the methods inside each stream heavy, so it takes time to complete them.
So far, I want to disable ListView selection, so I did:
<ListView IsEnabled="{Binding IsMatchListEnabled}"> private bool _isMatchListEnabled = true; public bool IsMatchListEnabled { get { return _isMatchListEnabled; } set { _isMatchListEnabled = value; OnPropertyChanged(); } }
before starting Thread IsMatchListEnabled = false; : IsMatchListEnabled = false; but I need to check if the whole thread is completed, and then do: IsMatchListEnabled = true; , in fact, if I turn on the ListView after all the threads, I get the ListView even on, because the Thread code is asynchronous, and the code outside Thread is synchronization, so this property is actually useless.
I tried to avoid this by creating an infinite loop like this:
while (true) { if (!_analysisThread.IsAlive && !_head2HeadThread.IsAlive && !_formThread.IsAlive) { IsMatchListEnabled = true; break; } }
this loop is placed after all threads have completed, but as you can imagine, this will freeze the application. Any solution?