I have a method called Do() it do some compute then save results in 2 different files and then do some other computes. As files may be large I wanted to update files by using task or something like that to prevent UI from freezing. I tried using TaskFactory and Wait and WaitAll but they freezed UI. other option is ContinueWith but there are many code after it that I can not move them up and I do not think moving all of them in ContinueWith be right thing to do. It can be easy by using async/await but I have to use .NetFramework4 so I can not use them. Other option that I think about it is to call a method and create a backgroundworker, in it update files and in Runworkercompleted event call a method to do remaining. But it is even uglier. Is there a better way for doing something in Separate thread/task in middle of a method without affecting other codes and UI thread? It is like doing all method works in separate thread/task and do not leave it until it be done completely without freezing UI.
Note: I have to use .NetFrameWork4.
method Do is:
public void Do()
{
//---------------
//other codes
//---------------
SaveResult1();
SaveResult2();
//---------------
//other codes that I can not move them up
//---------------
}
You can do it like this: