Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

"Unexpected error occurred" exception when adding a new channel to a channel group from a backgroundworker thread

I am developing an application in C# using Visual Studio 2012 on Windows 7 with the Measuement Studio .Net classes.

 

I have started to optimize my application by moving some of the more compute intensive operations out of the GUI thread and into BackgroundWorker threads.

 

Since I have done that I have started to get an "Unexpected Error Occurred" exception being thrown by the call to add a new TDMSChannel object to a TDMSChannelGroup. This code was working in my single threaded version.

 

The TDMSFile object that I am using, to get the ChannelGroup to add a new Channel to, was created in the GUI thread so I suspect that the exception is being caused by across threading issue.

 

I have tried moving the code to add the channel into an method that uses the Invoke mechanism to run the Channel Add opeation from the GUI thread but that does not fix the issue, I still get the exception.

 

Has anyone else seen this behavior and maybe have a solution.

 

Thanks in advance.

 

0 Kudos
Message 1 of 4
(5,608 Views)

Hello Eric

 

Are you sure you are implementing correct threading synchronization? You may want to take a look to this article:

 

http://msdn.microsoft.com/en-us/library/ms173179.aspx

 

As this looks like more a Visual Studio error than a Measurement Studio.

 

Regards

 

Mart G

0 Kudos
Message 2 of 4
(5,589 Views)

Found the issue!

 

Moving the code into the background worker thread was a Red Herring, it was not the problem. The actual issue was that the TDMS file I was working with had become corrupted, I could still read from it but when I attempted to write to it the TDMS class would throw an "Unexpected error occurred" exception.

 

If while developing new code your application does not properly close the TDMS file each time it is opened you may end up with a file that looks ok but cannot be modified. I would recommend using a copy of a known good TDMS file for testing and replacing it with a new copy anytime your application crashes or you kill it from the debugger.

Message 3 of 4
(5,553 Views)

Thanks for updating with your solution!

I had the same kind of strange error message, and spend almost one day struggling with it,

before I read this post.

 

To the NI guys: maybe some additional error checking could be done by your library to prevent these unspecific error messages?

 

Btw: I'm using Windows 7 32 bit with Visual Studio 2013 and Measurement Studio 2015.

0 Kudos
Message 4 of 4
(3,737 Views)