invoke

C# Invoke Powershell with pre-created object

安稳与你 提交于 2019-12-02 05:34:36
问题 I've just started out with PS and are writing some C# classes which I need to test from within PS. Please note that these classes are NOT CmdLets. I want to do something like this: var myCustomObj = new CustomObj { Message = "Hello world" }; var ps = Powershell.Create(); ps.AddCommand("Import-Module").AddParameter("Assembly", "MyCustomAsm"); ps.AddCommand("myCustomObj.Run()").AddParameter(myCustomObj); foreach(string str in ps.AddCommand("Out-String").Invoke<string>()) Console.WriteLine(str);

Blackberry - setPayloadText doesn't work

梦想的初衷 提交于 2019-12-02 05:22:14
I am trying to use the TexTMessage interface to prepare a SMS before invoking invokeApplication in order to open the SMS application with a prefilled message. The address (phone number) works well (it's prefilled) but the message body doesn't. Indeed it seems that the setPlayloadText method has no effect. Here is my code 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

How to properly call IDispatch::Invoke with a required BSTR* parameter

六眼飞鱼酱① 提交于 2019-12-02 02:49:30
问题 There are many examples of how to call IDispatch::Invoke with a BSTR* parameter. I have this working with many other "SomeType*" parameter but no matter what I try, I either get HRESULT of Type Mismatch, E_OUTOFMEMORY or an access violation. It seems to me I am doing something wrong with memory but I am following the different examples I have found... As a side note, the final "[out] UINT puArgErr" argument is never filled with the argument index that is causing the problem. However, I know

Invoking the click method of a button programmatically

核能气质少年 提交于 2019-12-02 02:44:17
Simple problem (I think): I want to be able to invoke a click method on a predefined object, specifically, the bindingNavigatorDeleteItem button on the standard c# BindingNavigator . I need to intercept the delete so that I can verify that the record is allowed to be deleted. If it is, I want to invoke the aforementioned click event which does a nice job of deleting said record. If the record is not eligible for deletion, I want to abort the delete. An engineering colleague of mine suggests that I simply add another button to the toolstrip and use it's click method (which, of course, I can get

__invoke() on callable Array or String

陌路散爱 提交于 2019-12-02 02:09:16
How would one write PHP code to call all "Callables" with __invoke() ? The desire here is pass by reference, which is deprecated with call_user_func[_array]() . I did see that there is a package out there, TRex\Reflection\CallableReflection , but this seems to utilize call_user_func() in the background, and would suffer the same issue. <?php function passthrough_invoke(callable $callback) { return $callback->__invoke(); } function passthrough_user(callable $callback) { return call_user_func($callback); } function test_func() { return "func_string\n"; }; class test_obj { function test_method()

Manipulating UI elements from within another thread

左心房为你撑大大i 提交于 2019-12-01 18:46:37
I'm trying to have a seperate thread in a WinForms C# application start a background worker which controls a ProgressBar (marquee). The issue is that when i try to set the bar to visible it just does nothing, and i've tried many forms of Invoke but they don't seem to help. The following method progressBarCycle is called from a separate thread. BackgroundWorker backgroundWorker = new BackgroundWorker(); public void progressBarCycle(int duration) { backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork); backgroundWorker.ProgressChanged += new ProgressChangedEventHandler

PHP Callable Object as Object Member

时光总嘲笑我的痴心妄想 提交于 2019-12-01 17:50:48
I have a class Logger which, among other things has a method Log . As Log is the most common use of the Logger instance, I have wired __invoke to call Log Another class, "Site" contains a member "Log", an instance of Logger. Why would this work: $Log = $this->Log; $Log("Message"); But not this: $this->Log("Message"); The former fails with "PHP Fatal error: Call to undefined method Site::Log()" Is this a limitation of the callable object implementation, or am I misunderstanding something? Same reasons you can't do this: $value = $this->getArray()["key"]; or even this $value = getArray()["key"];

PHP Callable Object as Object Member

时光怂恿深爱的人放手 提交于 2019-12-01 17:14:04
问题 I have a class Logger which, among other things has a method Log . As Log is the most common use of the Logger instance, I have wired __invoke to call Log Another class, "Site" contains a member "Log", an instance of Logger. Why would this work: $Log = $this->Log; $Log("Message"); But not this: $this->Log("Message"); The former fails with "PHP Fatal error: Call to undefined method Site::Log()" Is this a limitation of the callable object implementation, or am I misunderstanding something? 回答1:

Curious about the implementation of Control.Invoke()

走远了吗. 提交于 2019-12-01 16:40:21
What exactly does Control.Invoke(Delegate) do to get the delegate to run on the GUI thread? Furthermore, Its my understanding that invoke will block until the invoked function its done. How does it achieve this? I would like some good gritty details. I'm hoping to learn something interesting. Edit: The control implements ISynchronizeInvoke interface, You can make the same effect using the SynchronizationContext and call Post when you call Invoke . something like: public object Invoke(Delegate method, object[] args) { if (method == null) { throw new ArgumentNullException("method"); } object

BackgroundWorker still needs to call Invoke?

ε祈祈猫儿з 提交于 2019-12-01 11:34:20
In the last question Display progress bar while doing some work in C#? , people has recommend use of BackgroundWorker . I thought in BackgroundWorker DoWork method you can update the GUI directly, but why this function call need to be called using Invoke . toolTip.SetToolTip(button, toolTipText); The RunWorkerCompleted callback is marshalled onto the UI thread; DoWork is not. You should use the ReportProgress method to update the UI during DoWork processing. See: How to: Run an Operation in the Background You are mistaken, you can't call the UI thread directly from the handler for the DoWork