I really don't understand how this error occurs in this code. Please check the code yourself
void dispatcherTimer_Tick(object sender, EventArgs e) { string srUrl = lstLocalIndex[irLocalIndex] + lstMainIndex[irMainIndex].Replace("0;",""); Task.Factory.StartNew(() => { startNewWindow(srUrl); }); } void startNewWindow(string srUrl) { NewWindowThread<TitleWindow, string>(c => new TitleWindow(c), srUrl); }
Now this code is causing an error. I will also attach a screenshot
private void NewWindowThread<T, P>(Func<P, T> constructor, P param) where T : Window { Thread thread = new Thread(() => { T w = constructor(param); w.Show(); w.Closed += (sender, e) => w.Dispatcher.InvokeShutdown(); try { System.Windows.Threading.Dispatcher.Run(); } catch { } }); thread.SetApartmentState(ApartmentState.STA); try { thread.Start(); } catch { } }
This error causes an entire software error and stops working even if I call them in a new thread :(
The error of this line is: System.Windows.Threading.Dispatcher.Run ();
Also check the screenshot

C # 4.0 WPF
c # wpf access-violation unhandled-exception memory-corruption
MonsterMMORPG Apr 02 2018-12-12T00: 00Z
source share