It sounds likely that the ChangeDispacter is doing too much work for the UI thread.
If so, then one approach is to break the ChangeDispacter task down into smaller UI operations as shown in the code below. This should work as it appears that the MDelegate has no return value or it is not significant. And that is the approach the code is currently attempting to use.
However, if you are using .NET 4.5, then a far better solution, is to transform the ChangeDispacter method into an Async version and call it concurrently. That is shown in the second code block.
Using the current approach:
private void Change(object sender, ChangeArgs e)
{
if (channels.Count == 1)
{
foreach (int z in channels)
{
if (z == e.channel)
{
ChangeDispacterThreaded(e.channel, e.value);
}
}
}
}
public void ChangeDispacterThreaded(int channel, object value)
{
Slider1.Dispatcher.BeginInvoke(new MDelegate(ChangeDispacterUI_1)
, new object[] { channel, value });
Slider1.Dispatcher.BeginInvoke(new MDelegate(ChangeDispacterUI_2)
, new object[] { channel, value });
}
public void ChangeDispacterUI_1(int channel, object value)
{
}
public void ChangeDispacterUI_2(int channel, object value)
{
}
.NET 4.5 Using the asynch-concurrent approach
private async Task Change(object sender, ChangeArgs e)
{
if (channels.Count == 1)
{
foreach (int z in channels)
{
if (z == e.channel)
{
await ChangeDispacterThreaded(e.channel, e.value);
}
}
}
}
public async Task ChangeDispacterThreaded(int channel, object value)
{
await Slider1.Dispatcher.BeginInvoke(
new Action<int,object>((a,b) => ChangeDispacterUI_1(a,b))
, new object[] { channel, value });
await Slider1.Dispatcher.BeginInvoke(
new Action<int, object>((a, b) => ChangeDispacterUI_1(a, b))
, new object[] { channel, value });
}
public void ChangeDispacterUI_1(int channel, object value)
{
}
public void ChangeDispacterUI_2(int channel, object value)
{
}