本文整理汇总了C#中System.Windows.Forms.Control.invokeOnThread方法的典型用法代码示例。如果您正苦于以下问题:C# Control.invokeOnThread方法的具体用法?C# Control.invokeOnThread怎么用?C# Control.invokeOnThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Control
的用法示例。
在下文中一共展示了Control.invokeOnThread方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addNodeToTreeNodeCollection
/// <summary>
/// Async Thread safe way to add nodes to TreeViews
/// </summary>
public static void addNodeToTreeNodeCollection(Control controlInCorrectThread, TreeNodeCollection targetTreeNodeCollection, TreeNode newNode, int maxNodesToAdd)
{
// if (controlInCorrectThread.okThread(delegate { addNodeToTreeNodeCollection(controlInCorrectThread,targetTreeNodeCollection, newNode); }))
controlInCorrectThread.invokeOnThread(
() =>
{
if (maxNodesToAdd == -1 || targetTreeNodeCollection.Count < maxNodesToAdd)
if (Thread.CurrentThread.IsAlive)
targetTreeNodeCollection.Add(newNode);
});
}
示例2: mapFile
public static string mapFile(string fileToMap,Control hostControl)
{
if (hostControl != null)
return (string) hostControl.invokeOnThread(() =>
{
if (fileToMap != null && false == File.Exists(fileToMap))
{
var resolvedFileMapping =
new resolvedFileMapping(fileToMap);
if (resolvedFileMapping.resolveFileMapping())
return resolvedFileMapping.sMappedFile;
else
DI.log.error(
"in SourceCodeMappingsUtils.mapFile, could not map file: {0}",
fileToMap);
}
return fileToMap;
});
return mapFile(fileToMap);
}
示例3: SetFocusOnControl
public static void SetFocusOnControl(Control targetControl, int sleepBeforeFocus)
{
// first start a separate thread to wait before jumping into the targetControl to set the focus
O2Thread.mtaThread(
()=>
{
Thread.Sleep(sleepBeforeFocus);
targetControl.invokeOnThread(()=>targetControl.Focus());
});
}
示例4: findParentThatHostsControl
public static Control findParentThatHostsControl(Control controlToFind)
{
return controlToFind.invokeOnThread(
() =>{
if (controlToFind != null)
{
IEnumerable<Control> results = from Control control in controlToFind.Parent.Controls
where control == controlToFind
select controlToFind.Parent;
if (results.Count() == 1)
return results.First();
findParentThatHostsControl(controlToFind.Parent);
}
return null;
});
}