سؤال

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