我正在使用后台工作人员,我认为存在跨线程问题。但我无法解决。
我的代码在这里
private void bgworkerGameLoad_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
var arg = e.Argument.ToString();
var liste = webHelper.ShowGame("http://www.abx.com/" + arg);
txtHowToPlay.Invoke(new Action(() => txtHowToPlay.Text = String.Format("Oyun Bilgi: {0}", liste[0])));
txtInfo.Invoke(new Action(() => txtInfo.Text = String.Format("Nasıl Oynanır: {0}", liste[1])));
bgworkerGameLoad.ReportProgress(0,liste[2]);
}
private void bgworkerGameLoad_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
if (FlashPlayerActive)
UnLoad();
string url="";
Invoke(new MethodInvoker(() =>
{
url= e.UserState.ToString();
Thread.Sleep(2);
}));
axShockwaveFlash1.Movie = url;
LoadFlash();
pbWaitForChannelLoading.Visible = false;
axShockwaveFlash1.Play();
}
问题是我无法为我的 shocwaveplayer 获取 e.UserState.ToString()。我使用了本地字符串变量,但结果相同。
在program.cs中发生targetofaninvocation异常
Application.Run(new FrmMain());;
但该代码在 frmMain.cs
这是异常的详细信息
System.Reflection.TargetInvocationException 未处理 Message=Exception 已被调用的目标抛出。Source=mscorlib StackTrace: 在 System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] 参数, CultureInfo 文化, Boolean skipVisibilityChecks) 在 System.Delegate.DynamicInvokeImpl(Object[] args) 在 System.Windows.Forms 。控制。Program.Main() in c:\Users.................\Program.cs:line 23 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain .ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback 回调,对象状态)在 System.Threading.ThreadHelper.ThreadStart() InnerException:System.NullReferenceException 消息=对象引用未设置为对象的实例。Source=System.Windows.Forms StackTrace:在 System.Windows.Forms.Control.MarshaledInvoke(控制调用者,委托方法,
我的错误是什么?我尝试使用委托,但它是一样的..