Skip to main content

Posts

Showing posts from May, 2015

Continue executing code after calling ShowDialog() using C#

In  C# windows form application using ShowDialog() a user can show a form as modal dialog. Here we cannot access the rest application or continue execution of the code until the modal dialog is closed. Sometimes we need to show modal dialog to user and we need to perform some background operations with parent form control without closing the dialog box. For example - we are doing some calculation and on the basis of these calculation we are moving the progress bar control on dialog box. Here is the c# code by which user can continue executing code after showing modal dialog using ShowDialog() - ReaderWriterLockSlim ScanLock = new ReaderWriterLockSlim(); private void Form1_Load ( object sender, EventArgs e) { ScanLock.EnterWriteLock(); UIThread(()=> { WindowsFormsSynchronizationContext.Current.Post(_ => { Form2 frm = new Form2(); frm.ShowDialog();