invoke

MethodInvoker vs Action for Control.BeginInvoke

五迷三道 提交于 2019-11-26 12:16:58
问题 Which is more correct and why? Control.BeginInvoke(new Action(DoSomething), null); private void DoSomething() { MessageBox.Show(\"What a great post\"); } or Control.BeginInvoke((MethodInvoker) delegate { MessageBox.Show(\"What a great post\"); }); I kinda feel like I am doing the same thing, so when is the right time to use MethodInvoker vs Action , or even writing a lambda expression? EDIT: I know that there isn\'t really much of a difference between writing a lambda vs Action , but

How to call a function by its name (std::string) in C++?

北城以北 提交于 2019-11-26 12:03:29
问题 I wonder if there is a simple way to call a function from a string. I know a simple way, using \'if\' and \'else\'. int function_1(int i, int j) { return i*j; } int function_2(int i, int j) { return i/j; } ... ... ... int function_N(int i, int j) { return i+j; } int main(int argc, char* argv[]) { int i = 4, j = 2; string function = \"function_2\"; cout << callFunction(i, j, function) << endl; return 0; } This is the basic approach int callFunction(int i, int j, string function) { if(function

Unable to access UNC Paths in Powershell remote session

孤街浪徒 提交于 2019-11-26 11:33:37
问题 I am unable to access the UNC paths on my servers in a Powershell remote session from my local machine. I am able to use them from Servers Cmd prompt directly. Actually, I have logged into the server and mapped a UNC path as local drive (say X:). Used Reconnect on Login option. I have a batch file which resides in this X: drive, I want to run it remotely using invoke command from my local script. But, it fails. It says \"Cannot find drive. A drive with name X doesn\'t exist\". Also, when I

How does the event dispatch thread work?

旧巷老猫 提交于 2019-11-26 11:24:23
问题 With the help of people on stackoverflow I was able to get the following working code of a simple GUI countdown (which just displays a window counting down seconds). My main problem with this code is the invokeLater stuff. As far as I understand invokeLater , it sends a task to the event dispatching thread (EDT) and then the EDT executes this task whenever it \"can\" (whatever that means). Is that right? To my understanding, the code works like this: In the main method we use invokeLater to

C# DllImport with C++ boolean function not returning correctly

不羁岁月 提交于 2019-11-26 09:35:11
问题 I have the following function in a C++ DLL extern \"C\" __declspec(dllexport) bool Exist(const char* name) { //if (g_Queues.find(name) != g_Queues.end()) // return true; //else // return false; return false; } Inside my C# class I have the following: [DllImport(\"Whisper.dll\", EntryPoint=\"Exist\", CallingConvention=CallingConvention.Cdecl)] public static extern bool Exist(string name); Yet, whenever I call my function it ALWAYS returns true, even when I commented out my little function and

How do I invoke a private static method using reflection (Java)?

筅森魡賤 提交于 2019-11-26 09:29:41
问题 I would like to invoke a private static method. I have its name. I\'ve heard it can be done using Java reflection mechanism. How can I do it? EDIT: One problem I encountered when trying to invoke the method is how to specify the type of its argument. My method receives one argument and its type is Map. Therefore I cannot do Map<User, String>.TYPE (In run time there\'s no such a thing as Map because of Java Type erasure). Is there another way to get the method? 回答1: Let's say you want to call

Using the C# Dispatcher

醉酒当歌 提交于 2019-11-26 09:26:17
问题 I\'m building a chat client and am not 100% sure on how to use the dispatcher . So the question is I have a method as such: public void LostConnection() { myGUI.chatBox.AppendText(\"Lost connection to room: \"+ myGUI.UsernameText.ToString() + \"\\r\\n\"); } Do i need to surrond the statement within (myGUI.chatBox... ) with a Dispatcher.Invoke ? I appreciate any help. 回答1: Your app has a main UI thread (usually ManagedThreadId==1 ). Typically in a chat app your events will come in on other

Difference Between Invoke and DynamicInvoke

那年仲夏 提交于 2019-11-26 05:57:22
问题 What is the difference between Invoke and DynamicInvoke in delegates? Please give me some code example which explain difference between that two methods. 回答1: When you have a delegate instance, you might know the exact type, or you might just know that it is a Delegate . If you know the exact type, you can use Invoke , which is very fast - everything is already pre-validated. For example: Func<int,int> twice = x => x * 2; int i = 3; int j = twice.Invoke(i); // or just: int j = twice(i);

Javascript dynamically invoke object method from string

那年仲夏 提交于 2019-11-26 05:26:41
问题 Can I dynamically call an object method having the method name as a string? I would imagine it like this: var FooClass = function() { this.smile = function() {}; } var method = \"smile\"; var foo = new FooClass(); // I want to run smile on the foo instance. foo.{mysterious code}(); // being executed as foo.smile(); 回答1: if the name of the property is stored in a variable, use [] foo[method](); 回答2: Properties of objects can be accessed through the array notation: var method = "smile"; foo

Is it appropriate to extend Control to provide consistently safe Invoke/BeginInvoke functionality?

末鹿安然 提交于 2019-11-26 05:26:13
问题 In the course of my maintenance for an older application that badly violated the cross-thread update rules in winforms, I created the following extension method as a way to quickly fix illegal calls when I\'ve discovered them: /// <summary> /// Execute a method on the control\'s owning thread. /// </summary> /// <param name=\"uiElement\">The control that is being updated.</param> /// <param name=\"updater\">The method that updates uiElement.</param> /// <param name=\"forceSynchronous\">True