WPF XAML demo: Difference between revisions

Jump to navigation Jump to search
6 bytes removed ,  12:36, 7 May 2020
m
Line 613: Line 613:
The author has taken the prefix '⍝∇' instead of '⍝' because in production code you will probably want to erase all the comments in your runtime WS because they are useless and it is helping to obfuscate the code while taking less space.
The author has taken the prefix '⍝∇' instead of '⍝' because in production code you will probably want to erase all the comments in your runtime WS because they are useless and it is helping to obfuscate the code while taking less space.
==== With a DispatcherTimer ====
==== With a DispatcherTimer ====
If you have a repetitive task to be executed on the UI thread then you can use a [[https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer(v=vs.110).aspx|DispatcherTimer]] like this:
If you have a repetitive task to be executed on the UI thread then you can use a [https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer(v=vs.110).aspx DispatcherTimer] like this:
<source lang=apl>
<source lang=apl>
     ⎕USING∪←'System.Windows,WPF/WindowsBase.dll' 'System,mscorlib.dll'
     ⎕USING∪←'System.Windows,WPF/WindowsBase.dll' 'System,mscorlib.dll'
Line 623: Line 623:
Note that since the <source lang=apl inline>DispatcherTimer</source> is executed on the UI thread you cannot have a long callback because it will freeze the UI during its execution.
Note that since the <source lang=apl inline>DispatcherTimer</source> is executed on the UI thread you cannot have a long callback because it will freeze the UI during its execution.
==== With a BackgroundWorker ====
==== With a BackgroundWorker ====
The .NET framework provides a simple way to get started in threading with the [[https://msdn.microsoft.com/fr-fr/library/cc221403(v=vs.95).aspx|BackgroundWorker]] component. This wraps much of the complexity and makes spawning a background thread relatively safe. It offers several features which include spawning a background thread, the ability to cancel the background process before it has completed, and the chance to report the progress back to your UI. The <source lang=apl inline>BackgroundWorker</source> is an excellent tool when you want multithreading in your application with access to the UI thread, mainly because it's so easy to use.
The .NET framework provides a simple way to get started in threading with the [https://msdn.microsoft.com/fr-fr/library/cc221403(v=vs.95).aspx BackgroundWorker] component. This wraps much of the complexity and makes spawning a background thread relatively safe. It offers several features which include spawning a background thread, the ability to cancel the background process before it has completed, and the chance to report the progress back to your UI. The <source lang=apl inline>BackgroundWorker</source> is an excellent tool when you want multithreading in your application with access to the UI thread, mainly because it's so easy to use.


An example is included in this namespace. It is inspired by this [[http://www.wpf-tutorial.com/misc/multi-threading-with-the-backgroundworker/|article]].  You start the example by doing:
An example is included in this namespace. It is inspired by [http://www.wpf-tutorial.com/misc/multi-threading-with-the-backgroundworker/ this article].  You start the example by doing:
<source lang=apl>
<source lang=apl>
       BackgroundWorkerSample& 1000
       BackgroundWorkerSample& 1000

Navigation menu