How to create an asynchronous method

前端 未结 8 2095
离开以前
离开以前 2020-12-22 20:18

I have simple method in my C# app, it picks file from FTP server and parses it and stores the data in DB. I want it to be asynchronous, so that user perform other operations

8条回答
  •  醉梦人生
    2020-12-22 20:42

    ThreadPool.QueueUserWorkItem is the quickest way to get a process running on a different thread.

    Be aware that UI objects have "thread affinity" and cannot be accessed from any thread other than the one that created them.

    So, in addition to checking out the ThreadPool (or using the asynchronous programming model via delegates), you need to check out Dispatchers (wpf) or InvokeRequired (winforms).

提交回复
热议问题