Pergunta

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?

Foi útil?

Solução

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/

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top