0

I inherited a legacy Winforms/C# application. The app uses several different grids spread across multiple tabs. In order the speed up load time/query performance, fetching data to for data sources is done asynchronously through spawned threads.

When running the application in Visual Studio 2019, I get several cross thread exceptions as the system fires events when the data sources are set/reset. These events of course fire on events which are not on the main UI thread.

I only see these exceptions while debugging in Visual Studio. I know in years past it was a BAD IDEA/DESIGN to do so and whenever we came across instances, we would wrap access with Invoke()/BeginInvoke().

Given these exceptions get "eaten" when running the application outside of Visual Studio, is this still the case? .. or is it considered a benign/safe exception?

JohnB
  • 3,921
  • 8
  • 49
  • 99
  • 1
    I have had similar situations where the cross thread error showed in visual studio but ran fine (majority of the time) in the executable. In some situations the application would crash due to the cross thread exception, but very infrequent. Solution was of course to invoke the UI calls. So even when it seems to run fine, you open the door to these exceptions during runtime. – hijinxbassist Dec 16 '21 at 17:10

1 Answers1

0

I only see these exceptions while debugging in Visual Studio.

Because CheckForIllegalCrossThreadCalls defaults to Debugger.IsAttached

enter image description here

Source Code link

I know in years past it was a BAD IDEA/DESIGN to do so and whenever we came across instances, we would wrap access with Invoke()/BeginInvoke()

You should still do so, or work out some other way of marshaling the work of updating the control onto the thread that created the control

Given these exceptions get "eaten" when running the application outside of Visual Studio, is this still the case?

It is still the case; fix these problems

or is it considered a benign/safe exception?

I don't recall ever coming across anyone who thought it was..

Charlieface
  • 52,284
  • 6
  • 19
  • 43
Caius Jard
  • 72,509
  • 5
  • 49
  • 80