What is DispatcherTimer in WPF?
_timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(2000); _timer.Tick += new EventHandler(delegate(object s, EventArgs a) { statusText.Text = string.Format( "Timer Ticked: {0}ms", Environment.TickCount); }); _timer.Start();
src: http://msdn.microsoft.com/en-us/magazine/cc163328.aspx
Learning Part 1-Memory/Lock tips.
- DispatcherTimer issue: http://geekswithblogs.net/dotnetrodent/archive/2009/11/05/136015.aspx
- Memory leaked caused by event handler http://blogs.msdn.com/b/abhinaba/archive/2009/05/05/memory-leak-via-event-handlers.aspx
- Lock usage(based on common misuses found in smart code) From MSDN: http://msdn.microsoft.com/en-us/library/c5kehkcz(v=vs.80).aspx
- lock calls Enter at the beginning of the block and Exit at the end of the block.In general, avoid locking on a public type, or instances beyond your code’s control. The common constructs
lock (this)
,lock (typeof (MyType))
, andlock ("myLock")
violate this guideline:
lock (this)
is a problem if the instance can be accessed publicly. (A few places in smart still does this.)lock (typeof (MyType))
is a problem ifMyType
is publicly accessible.lock(
“
myLock
”
)
is a problem since any other code in the process using the same string, will share the same lock.
Best practice is to define a private object to lock on, or a private static object variable to protect data common to all instances.
- Don’t use lock if only one thread is involved.
a) Don’t lock on code run only on one UI thread. (use a Boolean flag to prevent re-entry if that is the intention)
- Know what you are try to lock, in other word, keep the lock scope as tight as possible.
a) Lock a large code block (or a method that does a lot is a problem, even worse, if the method uses pushframe that waits for messages)
b) Don’t try to use lock to synchronize action/method, use thread safe producer-consumer queue.(a live example is Dispatcher in the UI thread).
(Few learnings from my team, I’m not the original author.. credit goes to my fellow teammate. thkx)
URLDownloadToCacheFile failed with HRESULT ‘-2146697208’
One of my team mate faced this issue and not able to install Smart Clickonce coz of this err. On searching i found this information somewhere in the 3’rd page of the search.. damm it.
http://support.microsoft.com/kb/934387
-
Recent
- The ID token is not yet valid. Make sure your computer’s time and time zone are both correct. Current epoch = 1689517128
- .NET Core – How to create a .NET GUI app which runs across the platform
- AKS 2022 updates
- Linux firewall and connectivity issues
- Microsoft Ignite (Sep22-24) event recap & On-demand sessions
- [Linux] Steps to install and configure sysstat package for monitoring.
- Azure Security Enablement – Centralized place for all the links
- Presenting tech session with stories [linkedin learning notes]
- gRPC using .NET core notes
- .NET in 2020 (Build recap)
- #KubeCon CNCF – North America 2019 watchlist
- AKS CLI Sheetcheat for the labs
-
Links