本文整理汇总了C#中ParameterizedThreadStart.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterizedThreadStart.Invoke方法的具体用法?C# ParameterizedThreadStart.Invoke怎么用?C# ParameterizedThreadStart.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterizedThreadStart
的用法示例。
在下文中一共展示了ParameterizedThreadStart.Invoke方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadAndSaveAsynchronous
/// <summary>Downloads bytes from the specified URL and saves them to a file.</summary>
/// <param name="url">The URL.</param>
/// <param name="file">The file name.</param>
/// <param name="days">If the file already exists and was modified during the last so and so days, the download will be bypassed.</param>
/// <param name="callback">The function to execute once the data has been saved to the file, or a null reference. The argument in the callback function is of type System.String and contains the file name.</param>
internal static void DownloadAndSaveAsynchronous(string url, string file, double days, ParameterizedThreadStart callback)
{
bool download;
if (File.Exists(file)) {
try {
DateTime lastWrite = File.GetLastWriteTime(file);
TimeSpan span = DateTime.Now - lastWrite;
download = span.TotalDays > days;
} catch {
download = true;
}
} else {
download = true;
}
if (download) {
ThreadStart start = new ThreadStart(
() => {
try {
byte[] bytes = DownloadBytesFromUrl(url);
string directory = Path.GetDirectoryName(file);
try {
Directory.CreateDirectory(directory);
File.WriteAllBytes(file, bytes);
} catch { }
if (callback != null) {
callback.Invoke(file);
}
} catch { }
}
);
Thread thread = new Thread(start);
thread.IsBackground = true;
thread.Start();
} else if (callback != null) {
callback.Invoke(file);
}
}
示例2: RunTask
public static Thread RunTask(ParameterizedThreadStart task, params object[] parameters)
{
if (_semaphore == null)
{
if (MaxThreads == 0)
MaxThreads = 10;
_semaphore = new Semaphore(MaxThreads, MaxThreads);
}
_semaphore.WaitOne();
var t = new Thread(delegate()
{
try
{
task.Invoke(parameters);
}
finally
{
_semaphore.Release();
//Remove thread from _thread list
lock (_threads)
{
if (_threads.Contains(Thread.CurrentThread))
_threads.Remove(Thread.CurrentThread);
}
}
});
t.IsBackground = true;
lock (_threads)
_threads.Add(t);
t.Start();
return t;
}
示例3: ImportDataFromAccessToolStripMenuItem_Click
/// <summary>
/// Import data from access
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ImportDataFromAccessToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!SystemManager.MONO_MODE)
{
//MONO not support this function
OpenFileDialog AccessFile = new OpenFileDialog();
AccessFile.Filter = MongoDBHelper.MdbFilter;
if (AccessFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MongoDBHelper.ImportAccessPara parm = new MongoDBHelper.ImportAccessPara();
parm.accessFileName = AccessFile.FileName;
parm.currentTreeNode = trvsrvlst.SelectedNode;
parm.strSvrPathWithTag = SystemManager.SelectObjectTag;
ParameterizedThreadStart Parmthread = new ParameterizedThreadStart(MongoDBHelper.ImportAccessDataBase);
Thread t = new Thread(Parmthread);
Parmthread.Invoke(parm);
}
}
}
示例4: Filter
/// <summary>
/// Adapts the html source returned by the XWiki server and makes it usable by Word using a local html file.
/// </summary>
/// <param name="xmlDoc">A reference to the xml dom.</param>
public void Filter(ref XmlDocument xmlDoc)
{
XmlNodeList images = xmlDoc.GetElementsByTagName("img");
foreach (XmlNode node in images)
{
if (node.NodeType == XmlNodeType.Element)
{
XmlAttribute vshapesAttr = node.Attributes["v:shapes"];
if (vshapesAttr != null)
{
node.Attributes.Remove(vshapesAttr);
}
//remove parameters from URLs
String src = node.Attributes["src"].Value.Split('?')[0];
//Creating an additional attribute to help identifing the image in the html.
XmlAttribute attr = xmlDoc.CreateAttribute(ImageInfo.XWORD_IMG_ATTRIBUTE);
//Adding the attribute to the xhtml code.
Guid imgId = Guid.NewGuid();
attr.Value = imgId.ToString();
node.Attributes.Append(attr);
//Adding the image to the current image list.
ImageInfo imgInfo = new ImageInfo();
imgInfo.imgWebSrc = src;
if (node.Attributes["alt"] != null)
{
imgInfo.altText = node.Attributes["alt"].Value;
}
manager.States.Images.Add(imgId, imgInfo);
//Downloading image
if (src == "") continue;
if (src[0] == '/')
{
src = serverURL + src;
}
ParameterizedThreadStart pts = new ParameterizedThreadStart(DownloadImage);
String folder = localFolder + "\\" + localFilename + manager.AddinSettings.MetaDataFolderSuffix;
Object param = new ImageDownloadInfo(src, folder, imgInfo);
pts.Invoke(param);
src = folder + "\\" + Path.GetFileName(src);
src = "file:///" + src.Replace("\\", "/");
node.Attributes["src"].Value = src;
}
}
}