标签: invoke

c#.Net CF Form.Invoke引发ArgumentException

我从以下代码接收ArgumentException,我很难理解堆栈跟踪中的最后一个条目是

System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr,
                Binder binder, Object[] parameters, CultureInfo culture, 
                Boolean verifyAccess, StackCrawlMark& stackMark)
Run Code Online (Sandbox Code Playgroud)

当我逐步完成DeviceResponse时,按照我的预期填充并且目标位于并且符合预期,但每次都会抛出targetForm.Invoke

任何帮助将非常感激.

该事件定义为:

public static event EventHandler<MsgEventArgs<DeviceResponse>> DeviceResponseReceived;
Run Code Online (Sandbox Code Playgroud)

该代码正在引发该事件:

//Raise the event
if (DeviceResponseReceived != null)
{
    if (DeviceResponseReceived.Target is System.Windows.Forms.Form)
    {
         System.Windows.Forms.Form targetForm = DeviceResponseReceived.Target as System.Windows.Forms.Form;
         targetForm.Invoke(DeviceResponseReceived, new MsgEventArgs<DeviceResponse>(deviceResponse));
    }
}
Run Code Online (Sandbox Code Playgroud)

MsgEventArgs是从EventArgs派生的通用事件参数类:

public class MsgEventArgs<T> : EventArgs
{
    public MsgEventArgs(T value)
    {
        m_value = value;
    }
    private T m_value;
    public T Value
    {
        get { return m_value; }
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的表单中,我已在表单构造函数中注册了该事件:

DeviceResponse.DeviceResponseReceived += …
Run Code Online (Sandbox Code Playgroud)

c# events user-interface compact-framework invoke

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

你能在cfc中重新分配默认的<cfargument吗?

我正在调用cfc,cfc有一组默认参数:

<cfargument name="EMAIL_TEMPLATE_CODE" type="string" required="yes" hint="EMAIL_TEMPLATE_CODE is required.">
<cfargument name="EMAIL_TEMPLATE_SUBJECT" default="" type="string" required="no" hint="EMAIL_TEMPLATE_SUBJECT is NOT required.">
<cfargument name="EMAIL_TEMPLATE_BODY" default="" type="string" required="no" hint="EMAIL_TEMPLATE_BODY is NOT required.">
Run Code Online (Sandbox Code Playgroud)

我想做的是让这些参数不被要求(正如你可以通过required ="no"看到的那样)但是如果需要的话我想重新分配参数变量.

所以类似于:

<cfargument name="EMAIL_TEMPLATE_CODE" type="string" required="yes" hint="EMAIL_TEMPLATE_CODE is required.">
<cfargument name="EMAIL_TEMPLATE_SUBJECT" default="" type="string" required="no" hint="EMAIL_TEMPLATE_SUBJECT is NOT required.">
<cfargument name="EMAIL_TEMPLATE_BODY" default="" type="string" required="no" hint="EMAIL_TEMPLATE_BODY is NOT required.">

<cfinvoke component="#Request.CFCPath#.email_template" method="getEmailTemplate" returnvariable="getEmailTemplate">
    <cfinvokeargument name="EMAIL_TEMPLATE_CODE" value="#ARGUMENTS.EMAIL_TEMPLATE_CODE#">
</cfinvoke>

<cfif getEmailTemplate.RecordCount>
    <cfparam name="ARGUMENTS.EMAIL_TEMPLATE_SUBJECT" default="#getEmailTemplate.EMAIL_TEMPLATE_SUBJECT#" type="string">
    <cfparam name="ARGUMENTS.EMAIL_TEMPLATE_BODY" default="#getEmailTemplate.EMAIL_TEMPLATE_BODY#" type="string">
</cfif>
Run Code Online (Sandbox Code Playgroud)

但是我无法覆盖默认的ARGUMENTS变量.你能发现我做错了吗?

编辑:

我这样做是因为如果没有参数传递给cfc,我想创建一个.如果参数没有长度,我想我应该cfset一个局部变量?

<cfif Len(ARGUMENTS.EMAIL_TEMPLATE_ADDRESS_FROM)>
    <cfset EMailTemplateAddressFrom …
Run Code Online (Sandbox Code Playgroud)

coldfusion cfc invoke

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

调用UI委托会导致UI被隐藏

假设我有线程1,主窗口UI线程和线程2,一个模态形式的登录UI线程.

现在,线程1执行一段代码,并希望更改登录表单中的UI元素,以便调用委托来更改线程2中的某些内容.但是当它这样做时,登录表单将隐藏在主窗口后面,并且没有办法让我把它带回来.在任务栏上选择它并没有做任何事情,并且在调用方法的末尾写"Activate()"也没有做任何事情.

如何保持线程2的UI不被隐藏?

谢谢

.net user-interface multithreading delegates invoke

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

Delegate.DynamicInvoke太慢,如何更改调用Invoke?

我已经读过我应该创建并重用委托来获取对象属性的值.

我使用此代码来创建Delegate

    var objParm = Expression.Parameter(property.DeclaringType, "o");

    Type delegateType = typeof(Func<,>).MakeGenericType(property.DeclaringType, property.PropertyType);

    var lambda = Expression.Lambda(delegateType, Expression.Property(objParm, property.Name), objParm);

    return lambda.Compile()
Run Code Online (Sandbox Code Playgroud)

现在我只找到在"DynamicInvoke"调用中使用委托的方法.

现在我想将调用更改为"调用"导致性能原因.

我试过了

Delegate.Method.Invoke(invokedObject, null);
Run Code Online (Sandbox Code Playgroud)

但是在通话结束后我得到了例外

MethodInfo must be a RuntimeMethodInfo.
Run Code Online (Sandbox Code Playgroud)

我有每个属性的缓存类,我可以存储动态创建的委托.

我应该怎么做才能使用"普通"调用?

非常感谢.

c# delegates dynamic invoke .net-3.5

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

Java,一个接一个地调用对象上的方法(C#样式)

我想知道Java是否有这样的形式:

new Object().methodOne("This is the first method").methodTwo("Second attached method");
new String("Hello World  ").TrimEnd().Split(' ');
Run Code Online (Sandbox Code Playgroud)

谢谢

c# java syntax invoke method-call

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

黑莓 - setPayloadText不起作用

我试图在调用invokeApplication之前使用TexTMessage接口准备SMS,以便打开带有预填充消息的SMS应用程序.地址(电话号码)运行良好(已预先填写)但邮件正文却没有.实际上,似乎setPlayloadText方法没有任何效果.

这是我的代码

messConn = (MessageConnection)Connector.open("sms://");
TextMessage sMess=(TextMessage)messConn.newMessage(MessageConnection.TEXT_MESSAGE);
sMess.setAddress("sms://123456789");
sMess.setPayloadText(new String("ahah")); //doesn't seem to work
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(sMess));
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

文森特

sms blackberry invoke

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

Lambda表达式和InvokeOperation

我有这个代码,无法弄清楚如何通过Lambda表达式简化它?

public void LoadEntities(QueryBuilder<Device> query, Action<ServiceLoadResult<Device>> callback, object state)
{
    InvokeOperation<List<DivisionHierarchy>> obj = this.Context.GetAllDivisions();

    obj.Completed += new EventHandler(obj_Completed);   
}

void obj_Completed(object sender, EventArgs e)
{
    try
    {
        if (sender is InvokeOperation<List<DivisionHierarchy>>)
        {
            ObservableCollection<DivisionHierarchy> divisions = 
                new ObservableCollection<DivisionHierarchy>((sender as InvokeOperation<List<DivisionHierarchy>>).Value);
        }
    }
    catch  
    {                 
    }
} 
Run Code Online (Sandbox Code Playgroud)

.net c# lambda invoke wcf-ria-services

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

如何调用在线程中使用的代码

嗨,我想使用下面的代码作为一个线程.我有一些示例代码用于调用,但我不知道如何做到这一点,当我的组合框选择项目转到字符串.

这就是我所拥有的:

//My code
string cb1 = comboBox1.Items[comboBox1.SelectedIndex].ToString();

//Example 1
textBox2.Invoke((Action)(() => textBox2.Text = ""));

//Example 2
textbox2.Invoke((MethodInvoker)(delegate()
{
    //do something
}));
Run Code Online (Sandbox Code Playgroud)

c# multithreading combobox invoke

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

Java - 执行时间

我有这个代码:

public static void main(String[] args) {

    long f = System.nanoTime();

    int a = 10 + 10;

    long s =System.nanoTime();

    System.out.println(s - f);

    long g = System.nanoTime();

    int b = 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10;

    long h =System.nanoTime();

    System.out.println(h - g);

}
Run Code Online (Sandbox Code Playgroud)

使用此输出/ s:
测试1:

427
300
Run Code Online (Sandbox Code Playgroud)

测试2:

533
300
Run Code Online (Sandbox Code Playgroud)

测试3:

431
398
Run Code Online (Sandbox Code Playgroud)

根据我的测试场景,为什么线int b = 10 + 10 + 10 …

java time invoke execution

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

C#调用方法参数空引用异常

我想从字符串中调用一个方法,但它不允许我null作为参数传递.该方法不需要参数.

private void reconnect_Click(object sender, EventArgs e)
{
   string methodName = "data_load1";

   //Get the method information using the method info class
   MethodInfo mi = this.GetType().GetMethod(methodName);

   //Invoke the method
   mi.Invoke(this, null);
}
Run Code Online (Sandbox Code Playgroud)

data_load方法:

private void data_load1()
{
     this.dataTableAdapter.Fill(this.myDataSet.data);
}
Run Code Online (Sandbox Code Playgroud)

我收到NullReferenceException was unhandledmi.Invoke(this, null);.为什么这不让我传递null参数?

c# methods invoke nullreferenceexception winforms

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