< name="current_session_context_class" > thread_static < /property >
Apparently, it can have several settings:
- managed_web
- call
- thread_static
- web
References:
This blog is intended as a personal reference and a way of reinforcing knowledge gained through experience.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="RichTextWithBetterSpacing" TargetType="{x:Type RichTextBox}">
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontFamily" Value="Arial"/>
<Style.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
</Style>
</Style.Resources>
</Style>
</ResourceDictionary>
DateTime newDate = DateTime.SpecifyKind(oldDate, DateTimeKind.Unspecified);
using System;
using System.Threading;
using System.Windows.Threading; // WindowsBase.dll
namespace Test
{
public delegate void WriteTextDelegate(string message);
public class DispatcherTest
{
public void Start()
{
// Calling thread determines Dispatcher
m_Dispatcher = Dispatcher.CurrentDispatcher;
if (m_Timer == null)
m_Timer = new Timer(new TimerCallback(WriteText),
null, 1000, 2000);
else m_Timer.Change(1000, 2000);
}
public void Stop()
{
if (m_Timer != null)
m_Timer.Change(Timeout.Infinite, Timeout.Infinite);
}
public event WriteTextDelegate Message;
private Timer m_Timer;
private System.Windows.Threading.Dispatcher m_Dispatcher;
private void WriteText(object state)
{
m_Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
new WriteTextDelegate(OnMessage),
DateTime.Now.ToString());
}
private void OnMessage(string message)
{
if (Message != null)
Message(message);
}
}
}
using System;
using System.Threading;
namespace Test
{
public delegate void WriteSomeTextDelegate(string message);
public class SyncTest
{
public void Start()
{
// Calling thread determines SynchronizationContext
m_Context = SynchronizationContext.Current;
if (m_Timer == null)
m_Timer = new Timer(new TimerCallback(WriteText),
null, 1000, 2000);
else m_Timer.Change(1000, 2000);
}
public void Stop()
{
if (m_Timer != null)
m_Timer.Change(Timeout.Infinite, Timeout.Infinite);
}
public event WriteSomeTextDelegate Message;
private System.Threading.Timer m_Timer;
private System.Threading.SynchronizationContext m_Context;
private void WriteText(object state)
{
string message = DateTime.Now.ToString();
if (m_Context != null)
{
m_Context.Post(new SendOrPostCallback(PostCallback), message);
}
else OnMessage(message); // non-UI thread called Start
}
private void OnMessage(string message)
{
if (Message != null)
Message(message);
}
private void PostCallback(object state)
{
if (state is string)
{
OnMessage(state as string);
}
else throw new ArgumentException("State should be a string");
}
}
}