문제

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