by pietman
16. December 2011 14:46
System.Windows.Forms.Application.DoEvents();
d1f25aa8-3d82-4db1-8245-013269c1e718|0|.0
Tags:
Threading
by pietman
16. December 2011 12:22
lambda: Thread thread = new Thread(() => download(filename));
Thread thread = N
long way:
var thread = new Thread(new ParameterizedThreadStart(download));
others:
ThreadPool.QueueUserWorkItem( () => value = Process(value)); // use captured variable
// -- OR --
ThreadPool.QueueUserWorkItem( () =>
{
double val = value; // use explicit parameter
val = Process(val); // v is not changed
});
// -- OR --
ThreadPool.QueueUserWorkItem( (v) =>
{
double val = (double)v; // explicit var for casting
val = Process(val); // v is not changed
}, value);
BOOKS!
4d52ee67-3990-4877-b15c-79d9d44dd725|0|.0
Tags:
Threading
by pietman
1. October 2010 15:29
The following is a demonstration of how the invokeRequired can be used in Threading:
public partial class Form1 : Form
{
private System.Windows.Forms.TreeView treeView1;
public Form1()
{
this.treeView1 = new System.Windows.Forms.TreeView();
}
Microsoft.Win32.RegistryKey[] allkeys = new Microsoft.Win32.RegistryKey[]
{
Microsoft.Win32.Registry.ClassesRoot,
Microsoft.Win32.Registry.CurrentConfig,
Microsoft.Win32.Registry.CurrentUser,
Microsoft.Win32.Registry.DynData,
Microsoft.Win32.Registry.LocalMachine,
Microsoft.Win32.Registry.PerformanceData,
Microsoft.Win32.Registry.Users
};
private void RefreshRegistryListView()
{
if (treeView1.InvokeRequired)
{
treeView1.Invoke(new MethodInvoker(RefreshRegistryListView));
return;
}
else
UpdateTheTreeview(this, null);
}
private void UpdateTheTreeview(object Sender, EventArgs e)
{
TreeNode TN = new TreeNode();
Dictionary<string, TreeNode> RegistryNodes = new Dictionary<string,TreeNode>();
foreach (Microsoft.Win32.RegistryKey key in allkeys)
{
TreeNode T = TN.Nodes.Add(key.Name);
RegistryNodes.Add(key.Name, T);
}
foreach (Microsoft.Win32.RegistryKey key in allkeys)
{
Application.DoEvents();
try
{
foreach (string s in key.GetSubKeyNames())
RegistryNodes[key.Name].Nodes.Add(s);
}
catch { }
}
treeView1.Nodes.Clear();
foreach (TreeNode key in RegistryNodes.Values)
treeView1.Nodes.Add(key);
}
private void Form1_Load(object sender, EventArgs e)
{
Thread oThread = new Thread(new ThreadStart(RefreshRegistryListView));
oThread.Start();
}
}
ed7d203f-7aab-4506-aa5c-211aad8062dc|0|.0
Tags:
Threading