Tag: multithreading

Powershell可以并行运行命令吗?

我有一个PowerShell脚本来做一些图像批量处理,我想做一些并行处理。 Powershell似乎有一些后台处理选项,如开始工作,等待工作等,但我发现做并行工作的唯一好资源是写出脚本的文本并运行这些( PowerShellmultithreading ) 理想情况下,我想在.net 4中类似于foreach。 一些非常像: foreach-parallel -threads 4 ($file in (Get-ChildItem $dir)) { .. Do Work } 也许我会更好的下降到C#…

Android SDK AsyncTask doInBackground没有运行(子类)

截至2012年2月15日,我还没有find一个很好的解释,也没有理由为什么这不起作用。 最接近解决scheme的是使用传统的线程方法,但是为什么包含一个类似的东西(似乎不)在Android SDK中工作? Evenin'SO! 我有一个AsyncTask子类: // ParseListener had a callback which was called when an item was parsed in a // RSS-xml, but as stated further down it is not used at all right now. private class xmlAsync extends AsyncTask<String, RSSItem, Void> implements ParseListener 这是这样执行的: xmlAsync xmlThread = new xmlAsync(); xmlThread.execute("http://www.nothing.com"); 现在这个小类遇到了一点小错误。 以前它做了一些xmlparsing,但是当我注意到doInBackground()没有被调用的时候,我一行一行地把它解下来,最后以这个结尾: @Override protected […]

在Python中的调用者线程中捕获一个线程的exception

一般来说,我对Python和multithreading编程都很陌生。 基本上,我有一个脚本,将文件复制到另一个位置。 我想这将被放置在另一个线程,所以我可以输出….指示该脚本仍在运行。 我遇到的问题是,如果文件不能被复制,将会抛出exception。 如果在主线程中运行,这是可以的; 但是,具有以下代码不起作用: try: threadClass = TheThread(param1, param2, etc.) threadClass.start() ##### **Exception takes place here** except: print "Caught an exception" 在线程类本身,我试图重新抛出exception,但它不起作用。 我在这里看到有人问过类似的问题,但他们似乎都在做比我想做的更具体的事情(我不太了解提供的解决scheme)。 我已经看到人们提到sys.exc_info()的用法,但我不知道在哪里或如何使用它。 所有的帮助非常感谢! 编辑:线程类的代码如下: class TheThread(threading.Thread): def __init__(self, sourceFolder, destFolder): threading.Thread.__init__(self) self.sourceFolder = sourceFolder self.destFolder = destFolder def run(self): try: shul.copytree(self.sourceFolder, self.destFolder) except: raise

Android的AsyncTask线程限制?

我正在开发一个应用程序,我需要每次用户login到系统时更新一些信息,我也在电话中使用数据库。 对于所有这些操作(更新,从数据库中检索数据等),我使用asynchronous任务。 到目前为止,我不明白为什么我不应该使用它们,但是最近我经历过,如果我做了一些操作,我的一些asynchronous任务就停止在预执行上,不要跳到doInBackground。 这太离谱了,所以我开发了另一个简单的应用程序来检查什么是错的。 奇怪的是,当asynchronous任务的总数达到5时,我得到相同的行为,第6个人在预执行时停止。 在Activity / App上,android是否有asyncTasks的限制? 还是只是一些错误,应该报告? 有没有人遇到同样的问题,也许find了解决办法? 这里是代码: 简单地创build5个线程在后台工作: private class LongAsync extends AsyncTask<String, Void, String> { @Override protected void onPreExecute() { Log.d("TestBug","onPreExecute"); isRunning = true; } @Override protected String doInBackground(String… params) { Log.d("TestBug","doInBackground"); while (isRunning) { } return null; } @Override protected void onPostExecute(String result) { Log.d("TestBug","onPostExecute"); } } 然后创build这个线程。 它将进入preExecute并挂起(它不会去doInBackground)。 […]

在另一个线程的主线程中运行代码

在一个android服务中,我创build了一些线程来完成一些后台任务。 我有一个情况,线程需要在主线程的消息队列上发布特定的任务,例如一个Runnable 。 有没有办法获得主线程的Handler ,并从我的其他线程发布Message /运行到它? 谢谢,

带参数的ThreadStart

你如何开始在C#中的参数线程?

将CheckForIllegalCrossThreadCalls设置为false以避免debugging期间出现跨线程错误,是否安全?

在WinForms应用程序中,将CheckForIllegalCrossThreadCalls设置为FALSE以避免在debugging期间出现跨线程错误是安全的吗? CheckForIllegalCrossThreadCalls = false;

SwingUtilities.invokeLater是做什么的?

SwingUtilities.invokeLater做什么的? 它只是延迟其run方法内的代码块的run ? 在invokeLater函数中调用一个动作或者在我们想要执行的线程的末尾调用它,有什么区别? 任何人都可以帮助我真正的invokeLater函数吗?

在创build窗口句柄之前,不能在控件上调用Invoke或BeginInvoke

我有一个类似于Greg D在此讨论的SafeInvoke Control扩展方法(减去IsHandleCreated检查)。 我从System.Windows.Forms.Form调用它,如下所示: public void Show(string text) { label.SafeInvoke(()=>label.Text = text); this.Show(); this.Refresh(); } 有时(这个调用可能来自各种线程),导致以下错误: 发生System.InvalidOperationException Message =“Invoke或BeginInvoke不能在控件上调用,直到窗口句柄已被创build”。 Source =“System.Windows.Forms” StackTrace: at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args) at System.Windows.Forms.Control.Invoke(Delegate method) at DriverInterface2.UI.WinForms.Dialogs.FormExtensions.SafeInvoke[T](T control, Action`1 action) in C:\code\DriverInterface2\DriverInterface2.UI.WinForms\Dialogs\FormExtensions.cs:line 16 怎么回事,我该如何解决? 我知道它不是一个forms创造的问题,因为有时它会工作一次,下一次失败,那么问题是什么? PS。 我真的非常害怕WinForms,有没有人知道一系列文章解释整个模型,以及如何使用它?

在.NET中双重检查locking

我遇到这篇文章,讨论为什么在Java中打破了双重检查locking范例。 是范例有效的.NET(特别是C#),如果variables被宣布为volatile ?