标签: invoke

需要帮助在UI线程和C#中的另一个线程获取信息

我有一个服务器应用程序,通过网络接收信息并对其进行处理.服务器是多线程的,并且一次处理多个套接字,并且通过BeginInvoke和EndInvoke样式方法在没有我控制的情况下创建线程,这些方法由相应的回调函数链接.

我正在尝试创建一个表单,除了主GUI之外,它还显示一个ListBox项目,该项目由描述当前连接的套接字的项目填充.所以,我基本上要做的是使用其Add()函数向ListBox添加一个项目,从该线程运行相应的回调函数.我通过Controls属性访问我的表单控件 - IE:

(ListBox)c.Controls["listBox1"].Items.Add();
Run Code Online (Sandbox Code Playgroud)

当然,我不只是调用函数,我试过几种方法,我在这里和在网络上找到线程间的通信,包括MethodInvoker,使用delegate,与组合Invoke(),BeginInvoke()等似乎没有任何工作,我总是得到同样的异常告诉我,我的控件是从一个创建它以外的线程访问的.

有什么想法吗?

c# forms multithreading invoke

2
推荐指数
1
解决办法
1426
查看次数

从工作线程但不是主线程访问时,C# - 类字段为null

不确定我做错了什么:

class MyClass
{

    private EventInfo eventInfo;

    public void OnGenerateEvent(object sender, EventArgs e)
    { 
        // Called from *main* thread 

        // Load assembly and set eventInfo here
        eventInfo = ....GetEvent(...);
        eventInfo.AddEventHandler(source, handler);

        // Call to a static method in another assembly
        someMethodInfo.Invoke(null, null);

    }


    public void OnEventChanged(object sender, EventArgs args)
    {    
        // Called from a *worker* thread created 
        // by that static method in the other assembly

        eventInfo is null here !   

        // Trying to remove handler
        eventInfo.RemoveEventHandler(.....);

    }


    // But... …
Run Code Online (Sandbox Code Playgroud)

c# multithreading delegates invoke worker

2
推荐指数
1
解决办法
291
查看次数

VB.net在控件中调用属性更改

很多关于如何调用方法的例子,但是如何改变一个简单的属性?

为了演示,这里有一组非常简单的代码应该有所帮助.假设我需要从子表单设置visible属性,因此需要调用它:

Friend Sub activateItem(ByVal myItem As PictureBox)

    If myItem.InvokeRequired = True Then
        ????
    Else
        myItem.Visible = True
    End If

End Sub
Run Code Online (Sandbox Code Playgroud)

谢谢

vb.net properties invoke invokerequired

2
推荐指数
1
解决办法
7442
查看次数

从Visual Studio的工具栏调用exe

如何自定义Visual Studio工具栏中的按钮以运行某个可执行文件?

我使用的是VS2010,所以特定的答案会更好,尽管这可能是相同的交叉版本......

executable toolbar invoke visual-studio-2010 visual-studio

2
推荐指数
1
解决办法
289
查看次数

在Windows窗体中调用

有没有人有学习资源的链接使用Invoke?

我正在努力学习,但我看到的所有例子都无法适应我的目的.

.net invoke visual-c++ winforms

2
推荐指数
1
解决办法
1万
查看次数

ESB MULE将参数传递给java方法

我使用MULE版本3.3.0 CE,我想在入站中从头部获取一些值,然后将其传递给java方法,在java方法中对传递的值进行一些更改,最后我再次将它从java方法传递到出站? ???

inbound invoke payload mule

2
推荐指数
1
解决办法
8744
查看次数

尝试在远程计算机上调用 powershell 命令时出现错误

machineName 尝试通过以下方式使用 invoke-command 执行脚本:

 Invoke-command -filepath C:\scripts\GettMembers.ps1 -computername "machinename" -credential $Getcredential 
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

Connecting to remote server failed with the following error message : The WinRM client cannot process the request because the server name cannot be resolved. For more information, see the about_Remote_Troubleshooting Help topic.
Run Code Online (Sandbox Code Playgroud)

但我可以使用以下命令将计算机添加到本地计算机的受信任主机:

winrm set winrm/config/client `@{TrustedHosts="machineName"}' 
Run Code Online (Sandbox Code Playgroud)

powershell invoke powershell-2.0 powershell-remoting

2
推荐指数
1
解决办法
2万
查看次数

如何在变量的值变化上调用方法?

VoiceSearch()当my keyword(字符串变量)的值发生变化时,我想要调用方法.

private void VoiceSearch()
    {
        try
        {
            query.Append(keyword);

            Browser.Navigate(query.ToString());

        }
        catch (Exception)
        {
            throw;
        }
    }
Run Code Online (Sandbox Code Playgroud)

private string _keyword
public string keyword
{
  get
  { 
    return _keyword;
  }
  set
  {
    _keyword=value;
    VoiceSearch();
  }
}
Run Code Online (Sandbox Code Playgroud)

c# invoke listener

2
推荐指数
1
解决办法
166
查看次数

C#无法从'System.DateTime'转换为'object []'methodinfo.invoke

看起来我可能以错误的方式接近这个方向,而且方向非常受欢迎.

我试图Start在我的解决方案中触发所有方法.

Start方法采用日期时间

但是,当试图将日期作为"调用"的参数传递时,我遇到了错误

无法从System.DateTime转换为object []

欢迎任何想法

谢谢gws

scheduleDate = new DateTime(2010, 03, 11);

Type[] typelist = GetTypesInNamespace(Assembly.GetExecutingAssembly(), "AssetConsultants");

foreach (Type t in typelist)
{
    var methodInfo = t.GetMethod("Start", new Type[] {typeof(DateTime)} );
    if (methodInfo == null) // the method doesn't exist
    {
       // throw some exception
    }

    var o = Activator.CreateInstance(t);                 
    methodInfo.Invoke(o, scheduleDate);
}
Run Code Online (Sandbox Code Playgroud)

c# datetime createinstance invoke

2
推荐指数
1
解决办法
689
查看次数

Flutter 插件:调用 iOS 和 Android 方法,包括参数不起作用

在尝试我的第一个 Flutter 插件时,我尝试在 iOS 和 Android 世界中调用一个方法。我成功地能够在没有任何参数的情况下调用这样的方法。

但现在我想调用一个有参数的方法。

对于 iOS,由于某种原因,我无法让它工作。(也许这只是我一直在监督的一个自动完成的事情,因为 VSCode 没有自动完成我的 Swift 代码)。但也许是别的。请对此提供任何帮助。

这是我的代码:

我的库(F​​lutter-world)看起来像这样:

import 'dart:async';
import 'package:flutter/services.dart';

class SomeName {
  static const MethodChannel _channel =
      const MethodChannel('myTestMethod');

  static Future<String> get sendParamsTest async {
    final String version = await _channel.invokeMethod('sendParams',<String, dynamic>{
        'someInfo1': "test123",
        'someInfo2': "hello",
      });
    return version;
  }
}
Run Code Online (Sandbox Code Playgroud)

.

我的 swift 插件(iOS 世界)如下所示:

import Flutter
import UIKit

public class SwiftSomeNamePlugin: NSObject, FlutterPlugin {

  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "myTestMethod", binaryMessenger: …
Run Code Online (Sandbox Code Playgroud)

plugins android invoke swift flutter

2
推荐指数
1
解决办法
8063
查看次数