In the C# windows service currently implemented on our side, I have to include a method to perform file copy between the source and destination folders. I assume I shouldn't use the "background worker" since this is service-based and not UI-based. Should I include Asynchronous file IO operations? Or should I simply spawn a background thread?

有帮助吗?

解决方案

If the copy process is time consuming I would definitely suggest spanning a new background worker (thread) dedicated for the copy process so that the main service thread is free to do more important and meaningful stuff. Also you might need the copy background worker to expose a property to the main service thread the status of the copy process i.e. like not started, in progress, finished.

Check the Remarks section here:

msdn.microsoft.com/en-us/library/

其他提示

void WindowsService()
{
    // ...
    ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessFile), a);
    // ...
    // This code executes without waiting for ProcessFile to complete
}

private void ProcessFile(object a)
{
    // Perform File I/O here
}

via http://www.dotnetperls.com/threadpool

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top