invoke

List Collection object as Method Parameter

落爺英雄遲暮 提交于 2019-12-25 04:47:07
问题 Can anyone explain how the memory allocation is done while invoking a method having list collection as parameter. Since the code snippet below though apparently seems to result same but it is not resulting same. So I would like to know the difference in both the method call in terms of memory allocation. using System; using System.Collections.Generic; namespace ListSample { class ListSampleClass { static void Main(string[] args) { List<int> i = new List<int>(); i.Add(10); i.Add(15);

Adding nodes to treeview with Begin Invoke / Invoke

删除回忆录丶 提交于 2019-12-25 02:13:35
问题 I've been working through my first project and have had a great deal a valuable help from the guys on SO but now I'm stuck again. The below sub is used to add TreeNodes to a TreeView, excluding certain filetypes/names, upon addition of new data: Sub DirSearch(ByVal strDir As String, ByVal strPattern As String, ByVal tvParent As TreeNodeCollection) Dim f As String Dim e As String Dim tvNode As TreeNode Dim ext() As String = strPattern.Split("|"c) Try For Each d In Directory.GetDirectories

Invoke method in new thread (method name from string)?

谁都会走 提交于 2019-12-25 01:47:14
问题 Im trying to invoke a method on a new thread in a winforms c# app. But I need the method name to come from a string. Is it possible to do something like: public void newThread(string MethodName) { new Thread(new ThreadStart(MethodName)).Start(); } I've tried but cant seem to get this to work? Any advice would be much appreciated. 回答1: I am assuming you want to call method from within class itself. Type classType = this.GetType(); object obj = Activator.CreateInstance(classType) object[]

Invoking a Powershell script in C# results returning 0

浪尽此生 提交于 2019-12-24 21:27:14
问题 I'm creating a Windows Service that calls a Powershell script every minute. The Powershell script returns local system information. function MachineInformation { [hashtable]$machine = @{} $computerSystem = get-wmiobject Win32_ComputerSystem $machine.machine = $computerSystem.Name $machine.key = $computerSystem.Manufacturer [String]$machine.value = Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average [DateTime]$machine.timestamp = Get-Date Return

How can a PHP script detect if it has been invoked as a script or from the shell?

≯℡__Kan透↙ 提交于 2019-12-24 16:31:50
问题 I have a PHP script on a webserver. This file is invoked via the shell by another program but it could still be run by the webserver in response to an HTTP request. How can the script determine the way it was invoked? 回答1: There are lots of ways; I check if $_SERVER['HTTP_HOST'] is empty. I think the technically correct way is to see if php_sapi_name() returns cli 回答2: If it is executed from the shell then it won't have HTTP headers because it wasn't requested from HTTP protocols. 回答3: There

Using Invoke to handle calls from other threads. Is this a good pattern?

谁说胖子不能爱 提交于 2019-12-24 13:42:50
问题 After reading up on how to use Invoke to be able to update GUI elements from other threads I worked a bit with it, and has ended up with following approach to handle it. I am fairly certain I have overcomplicated the solution, but I do believe it is working as intended. The advantages I see with this approach is, that it allows multiple commands to be stored in short succession for consumption once the GUI thread is ready for it, and the order of the commands are maintained. The downside is

InvalideOperationException / invoke

点点圈 提交于 2019-12-24 07:07:50
问题 the following code is used to trigger invoke (code is reduced, i left out the error handling in this example to make it more clear) public static void InvokeIfNecessary(this Control control, MethodInvoker methodInvoker) { if (control != null && !control.IsDisposed && !control.Disposing) { if (control.InvokeRequired) { control.Invoke(methodInvoker); } else { methodInvoker(); } } } Normally it works fine, but sometimes if i call a method of a Form an InvalidOperationException is given.

invoke during background worker

爷,独闯天下 提交于 2019-12-24 05:05:27
问题 I need to invoke this: string input_ip_r = listView1.Items[lc].SubItems[1].Text; so I used if (InvokeRequired) { this.Invoke(new MethodInvoker(function)); return; } This worked but now I have put it into a BackgroundWorker and using this if (InvokeRequired) { this.Invoke(new MethodInvoker(bw.RunWorkerAsync)); return; } it gives an error that you can only run BackgroundWorker one at a time. So how do I invoke while in the Backgroundworker ? 回答1: I'm not quite sure how you want to use the

Diffrernce between BackgroundWorker.ReportProgress() and Control.BeginInvoke()

∥☆過路亽.° 提交于 2019-12-23 21:13:04
问题 What is the difference between options 1 and 2 in the following? private void BGW_DoWork(object sender, DoWorkEventArgs e) { for (int i=1; i<=100; i++) { string txt = i.ToString(); if (Test_Check.Checked) //OPTION 1 Test_BackgroundWorker.ReportProgress(i, txt); else //OPTION 2 this.BeginInvoke((Action<int, string>)UpdateGUI, new object[] {i, txt}); } } private void BGW_ProgressChanged(object sender, ProgressChangedEventArgs e) { UpdateGUI(e.ProgressPercentage, (string)e.UserState); } private

Controlled exception handling in dynamic invocations with variable numbers of parameters

喜欢而已 提交于 2019-12-23 18:11:09
问题 In a thread resolved yesterday, @hvd showed me how to get "control" over exception handling by .Invoke when dealing with delegates of unknown type (an issue seen in libraries like Isis2, where the end-user provides polymorphic event handlers and the library type-matches to decide which to call). Hvd's suggestion revolved around knowing how many arguments the upcall handler received and then using that information to construct a generic of the right type, which allowed him to construct a