我有以下代码:
Public Delegate Sub SetStatusBarTextDelegate(ByVal StatusText As String)
Private Sub SetStatusBarText(ByVal StatusText As String)
If Me.InvokeRequired Then
Me.Invoke(New SetStatusBarTextDelegate(AddressOf SetStatusBarText), StatusText)
Else
Me.labelScanningProgress.Text = StatusText
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
问题是,当我从另一个线程调用"SetStatusBarText"子时,InvokeRequired为True(应该是),但是然后我的线程在Me.Invoke语句中停止 - 暂停执行显示它们只是坐在那里,而不是实际调用任何东西.
关于为什么线程似乎害怕Invoke的任何想法?
我有一个关于MethodInfo.Invoke(o,null)的try/catch,并且VS2010被设置为永远不会在Exceptions上中断,但不幸的是调试器继续在Invoked方法内部中断.该方法是静态的,我已经安装了Phone Developer Beta.
这是错误还是开发人员错误?
谢谢!!
要弹出一个消息框,我正在使用MessageBox.Show(...).我通常将调用包装在一个Invoke中:
BeginInvoke (new Action (() => {
MessageBox.Show ());
}));
Run Code Online (Sandbox Code Playgroud)
(我删除了其他地方回答的原问题的一部分)
Invoke如果我从非GUI线程调用,是否总是需要将MessageBox调用包装在(Begin-)中?
我想调用一个操作UI线程控件的方法.我的代码有效,我想优化.我指的是MSDN上的这个资源.
根据那里,我们应该这样做
public delegate void myDelegate(int anInteger, string aString);
//...
Label1.Invoke(new myDelegate(myMethod), new Object[] {1, "This is the string"});
Run Code Online (Sandbox Code Playgroud)
这会在每次调用时引入一个孤立的委托对象(内存泄漏)吗?
当我像下面这样使用委托的静态实例时,然后在每次调用时使用此实例来调用:
private static _delegateInstance = new myDelegate(myMethod);
//...
Label1.Invoke(_delegateInstance , new Object[] {1, "This is the string"});
Run Code Online (Sandbox Code Playgroud)
这是线程安全吗?我认为这会有更好的性能,因为委托实例只创建一次?
当您检查方法调用(对象代理,方法方法,对象[] args)声明和doc语句时,您会发现输入参数代理
proxy-在其上调用方法的代理实例
当我在Java动态代理上进行测试时,我发现此代理是由vm生成的。所以我确实想知道为什么方法调用具有此参数,除了只有一个对象($ proxy0)之外,肯定没有其他东西,但是不要没有为我们的使用采取实际行动吗?
这是我多年来用来接收网络数据并在我的GUI(对话框,表单等)中使用它的技术.
public delegate void mydelegate(Byte[] message);
public ReceiveEngineCS(String LocalIpIn, String ReceiveFromIp, mydelegate d)
{
this.m_LocalIpIn = LocalIpIn;
this.m_ReceiveFromIp = ReceiveFromIp;
m_MainCallback = d;
SetupReceive();
m_Running = true;
//Create the Track receive thread and pass the parent (this)
m_RtdirReceiveThread = new Thread(new ParameterizedThreadStart(MessageRecieveThread));
m_RtdirReceiveThread.Start(this);
}
private void MessageRecieveThread(System.Object obj)
{
ReceiveEngineCS parent = (ReceiveEngineCS)obj;
while(parent.m_Running)
{
Byte[] receiveBytes = new Byte[1500];
try
{
receiveBytes = parent.m_ClientReceiver.Receive(ref parent.ipEndPoint);
parent.ThreadOutput(receiveBytes);
}
catch ( Exception e )
{
parent.StatusUpdate(e.ToString());
}
}
}
public void …Run Code Online (Sandbox Code Playgroud) 我使用Reflection(Method.Invoke)在.NET中调用函数.如果在此方法中发生错误并引发异常,则调试器不会显示实际代码,而是在Invoke()调用时停止.我可以从InnerException中检索异常信息,但与使用callstack的常规调试等相比,这非常不方便.可以像使用常规函数调用一样调试使用Method.Invoke调用的方法吗?
我们有一个应用程序,它使用MBeanServerConnection.invoke在MBean上调用各种远程方法.偶尔会有其中一种方法挂起.有没有办法让电话超时?如果通话时间太长,它将返回异常?
或者我是否必须将所有这些调用移动到单独的线程中,以便它们不会锁定UI并要求杀死应用程序?
任何人都可以帮助我,我有一个问题我试图让这个代码通过线程池在后台工作,但我似乎无法让它工作我一直收到此错误:
Cross-thread operation not valid: Control 'ListBox3' accessed
from a thread other than the thread it was created on.
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的代码:
private void DoWork(object o)
{
var list = ListBox3;
var request = createRequest(TxtServer.Text, WebRequestMethods.Ftp.ListDirectory);
using (var response = (FtpWebResponse)request.GetResponse())
{
using (var stream = response.GetResponseStream())
{
using (var reader = new StreamReader(stream, true))
{
while (!reader.EndOfStream)
{
list.Items.Add(reader.ReadLine());
ResultLabel.Text = "Connected";
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想将参数从.net客户端(Xamarin Android)传递到中心服务器。我通过方法“调用”在serverHub中调用服务器方法
HubServer代码:
public class ConversationHub : Hub{
public void SendChatMessage(int conversationId, int messageId, string messageText, bool isChat, LinkViewModel link)
// logic in the method
}
}
Run Code Online (Sandbox Code Playgroud)
我的实体
public class Message: Entity<int>
{
public string Url { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string ImgUrl { get; set; }
public virtual DetailMessage DetailMessage {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我想通过调用方法“ invoke”从.Net客户端传递到serverHub的对象(模型)。
public class LinkViewModel
{
public string Url { get; set; …Run Code Online (Sandbox Code Playgroud) invoke ×10
c# ×5
.net ×2
delegates ×2
winforms ×2
debugging ×1
dynamic ×1
ftp ×1
hang ×1
java ×1
jmx ×1
mbeans ×1
messagebox ×1
methodinfo ×1
networking ×1
proxy ×1
reflection ×1
signalr ×1
threadpool ×1
timeout ×1
vb.net ×1