Tag: WPF

Async / Await and SynchronicationContext (C# .Net)

Async / Await and SynchronicationContext (C# .Net)

Following innocuous looking async / await code will cause deadlock. To understand why, lets go into what await does in the above case. 1 Execution starts when the button is clicked and button1_Click event is fired on the UI thread. 2 The method, named LongRunningProcess, is invoked. 3 The lamda expression passed to Task.Run() executes in…

Read More Read More

Creating and Consuming Async methods (C# .Net)

Creating and Consuming Async methods (C# .Net)

The code we want to run asynchronously could either be CPU-bound or IO-bound. CPU-bound code keeps the CPU busy, requiring intensive processing, calculations etc. On the other hand, IO-bound code frees up the CPU while waiting for an IO operation to complete, for instance, get some data from a web service. Both kinds of asynchronous…

Read More Read More

Save and Load RichTextBox content in WPF

Save and Load RichTextBox content in WPF

The content of RichTextBox can be saved to a file (or any other stream) using TextRange class. It supports following four formats: System.Windows.DataFormats.Text : This saves the plain text in the content of RichTextBox excluding the formatting information and the images. System.Windows.DataFormats.Rtf : This saves the content in RTF format preserving formating information and images.…

Read More Read More