antosnowin
antosnowin

Reputation: 221

How to implement background process

How to run a background process in C# ? My requirement is to trigger a process from application which will run more than 30 mins . I have to show the updated status of process on screen every now and then. Could anyone suggest me a option in implementing this ? I have used WCF service in app.

Upvotes: 2

Views: 831

Answers (3)

Stef Kostas
Stef Kostas

Reputation: 37

If the long process is performed in the wcf service then run it using a background worker thread. Implement the notify progress and update a special table on a database (if there is one available). Create another method of the wcf service that checks and returns the state of the process (by reading the table) and call it from the app.

Edit:

Read about how to use Background worker. Use it in you service to run the heavy work. When you run the backround thread the service should return a response. Then update in the table that you can log the status of the work that the thread is on. Implement a timer on your application and call back on the service to read the status of the table.

Upvotes: 1

Sunil
Sunil

Reputation: 2905

My options are:


1. Use a backgroundworker process and perform the long running operation, mean while use a loading image to display work is in progress. Since you are using wcf service to get response back, it is difficult to show actual work progress.


2. Use ThreadPool.QueueUserWorkItem and delegate the long running process to threadpool threads. Then using Dispatcher.BeginInvoke update the UI.

Upvotes: 2

user2160375
user2160375

Reputation:

Read about One-Way calls and Callbacks.

Upvotes: 1

Related Questions