0

I have a program that copies a .zip file from one directory to another and unzips it. I use background worker for this.

Now the program works when it's started using the Visual Studio Start button or double clicked directly from Debug/program.exe, but when I copy this .exe file elsewhere, it starts properly doing some operations on the main thread, but the background worker doesn't seem to work.

Does anyone have any clue what's going on?

  • 1
    Are you using a third-party dll? Check your output directory to make sure you're not forgetting to copy any dlls with your exe. – Cory Jun 29 '15 at 14:14
  • [This may be relevant](http://stackoverflow.com/questions/258662/unhandled-exceptions-in-backgroundworker) – James Thorpe Jun 29 '15 at 14:14
  • Does your app need any input-param which you provided within the Debug-section within VS but not on your applications-call? – MakePeaceGreatAgain Jun 29 '15 at 14:15
  • as it doesn't work when you copy it to another place I'd check relative paths you could use. Also using try/catch in worker thread with logging exceptions can shed some light to the problem – Andriy Tylychko Jun 29 '15 at 14:17
  • Have you tried debugging the copy with Visual Studio? And are you copying the entire `/Debug` folder, or just the `.exe`? – Dan Puzey Jun 29 '15 at 14:34
  • Where is the code? It may contain any number of errors, throw exceptions, expect files in a certain (nonexistent) location. Please post the code. Also add logging to your program and record any exceptions – Panagiotis Kanavos Jun 29 '15 at 14:34
  • This is the worst case when you have deployed app not working. Consider to add at least basic error handling and logging to it so that you will be able to see **why** it is not working. Like it is now this is a broad question (it could be anything, starting from a stupid mistake in path and finishing app environment). – Sinatr Jun 29 '15 at 14:38

2 Answers2

0

Note to self: Always remember about third-party .dll files. I didn't have them in my output directory so the program wasn't working. Thanks @KoBE.

-1

It is looks like main thread finished, while Background thread do not finished his work. I think you need in main thread wait until background thread finished. You can use synchronization objects, for example Manual/Auto reset events. Scheme is simple: 1. In main thread you starts some background thread 2. Before main thread finished, it shall wait until background thread finished working 3. When background thread finished working, main thread can be finished too

In debug mode because of delays and breakpoints in main thread, background thread has enough time to finish his work

zzfima
  • 1,528
  • 1
  • 14
  • 21
  • This seems unlikely since the code works in VS or when run from the `Debug` folder. – Dan Puzey Jun 29 '15 at 14:34
  • Even simpler - just check the worker's status and events. This functionality is already provided. None of this will help though with coding errors, missing dlls etc. – Panagiotis Kanavos Jun 29 '15 at 14:35