A very basic explanation for threading in WPF?

前端 未结 3 1440
刺人心
刺人心 2021-01-06 11:49

I am very very new to WPF. I looked in the internet for several examples and tutorials about threading. They\'ve their own way to describe. But for naive like me, I want to

3条回答
  •  情歌与酒
    2021-01-06 12:34

    1. Multithreading hasn't anything to deal with the UI techinque you are choosing (Wpf or Winforms) - there are only slight differences when you have to switch to the UI thread to update your controls.

    2. According to your code sample, I must say, that there is no callback possibility from sql server to your program. If you want to have that feature, you have to implement the loop in C# not in a sql statement.

    Edit:

    According to the comment of OP I add a sample of background working and updating UI in foreground with TPL (Task Parallel Library):

    var task = new Task(() =>
        {
            // Do something very long ...
        });
    
    task.ContinueWith((previousTask) =>
        {
            label.Content = "Background work has finished.";
        },
        TaskScheduler.FromCurrentSynchronizationContext());
    
    label.Content = "Background work is running.";
    task.Start();
    

提交回复
热议问题