0

I am running a windows form base application, I am using background worker class for httpwebrequest. And using a webbrowser control, both are saving data to an excel sheet. It was working fine or maybe it was luck , now I see sometime the code gets stuck on the insert statement, it just goes in the

myCommand.ExecuteScalar();

does not come out .And after some time i see this:

The CLR has been unable to transition from COM context 0x7833a8 to COM context 0x7838b0 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.

The query where it gets stuck is:

try
{

    myCommand.CommandText = "Insert into [outputsheet$] (website,[facebook page],DealTitle,Dealtime,Dealprice,Dealvalue,Dealdiscount,Dealsaving,Linktitle,address,Category,[Type of Deal]) Values('" + 
        webaddress.Replace("'", "''") + "','" + facbookaddress.Replace("'", "''") + "','" + title.Replace("'", "''") + "','" + dealtime.Replace("'", "''") + "','" + 
        amount.Replace("'", "''") + "','" + value.Replace("'", "''") + "','" + discount.Replace("'", "''") + "','" + saving.Replace("'", "''") + "','" + 
        titleweb.Replace("'", "''") + "','" + address.Replace("'", "''") + "','" + categoryName.Replace("'", "''") + "','Now Deals')";
    myCommand.ExecuteScalar();

}
catch (Exception exp)
{

}

Kindly help, is there anything i need to do .How to avoid it. Thank you

LarsTech
  • 80,625
  • 14
  • 153
  • 225
confusedMind
  • 2,573
  • 7
  • 33
  • 74

2 Answers2

0

It might have something to do with MDA, as indicated in the post on this Microsoft forum (a few posts down, kind of have to fish for it): http://social.msdn.microsoft.com/forums/en-US/vsdebug/thread/8e04941e-32e1-4901-b360-4859106a5412

brazilianldsjaguar
  • 1,409
  • 1
  • 20
  • 45
0

Perhaps you might try encapsulating ExecuteNonQuery in lock() to avoid possibility of sending a request to excel while it is busy doing the previous one?

EDIT: example

If your code that does the insert is encapsulated in a class, you would do something like this:

static private object thisLock = new object();

and later:

lock(thisLock)
{
   myCommand.ExecuteNonQuery();
}

I haven't done a lot of multithreading so I might be way off the mark.

Nikola Markovinović
  • 18,963
  • 5
  • 46
  • 51