0

I have an application on vb.net 2017 , that reads from excel and save to database. When I process large data from excel , at some point the application stop , and inside visual studio I get this error :

Managed Debugging Assistant 'ContextSwitchDeadlock' : 'The CLR has been unable to transition from COM context 0x1b387fb0 to COM context 0x1b387e88 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.'

If I press Continue inside visual studio , the program continue to execute and finish the job without error.

But every time I have repeated the proces i get that error .

What can I do ?

Thank you !

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
Adriano
  • 57
  • 1
  • 9
  • You should not be doing such long-running tasks on the UI thread. The message is basically telling you that the UI thread was not able to do what it's primarily supposed to do, i.e. manage the UI, for a minute. You should use a `BackgroundWorker` or a `Task` to perform this work in the background so that the UI thread remains free to manage the UI. – jmcilhinney Dec 05 '18 at 00:00
  • @jmcilhinney Sorry but the application is working correctly. It's not dead , until the point that has processed around 100 records from excel , after this message is displayed and after I press continue he continues to add the remaining 3000 records without any problem. so it's doing the job without problem , so read from excel and write to database. I don't understand where is the problem ? – Adriano Dec 05 '18 at 00:08
  • Are you reading and processing this data on the UI thread? That is the problem. I already told you how to fix it. – jmcilhinney Dec 05 '18 at 00:12
  • @jmcilhinney sorry friend , is there any example somewhere about your solution ? Thank you ! – Adriano Dec 05 '18 at 00:18
  • I'm sure that there are plenty of examples. I'm surprised that you didn't find any when you opened your favourite search engine and entered the appropriate keywords. Maybe you misspelled something so you ought to try again. This site is not for the purposes of teaching broad topics. You need to do your own research first and try to implement what you think is appropriate. If it doesn't work, then is the time to post a question about that specific issue and you'll find plenty of people, myself included, ready and willing to help. – jmcilhinney Dec 05 '18 at 00:28

0 Answers0