public static void RegisterHotKey(Form _inForm, Keys _inKey) { int modifiers = 0; if ((_inKey & Keys.Alt) == Keys.Alt) { modifiers = modifiers | SystemWideHotKey.MOD_ALT; } if ((_inKey & Keys.Control) == Keys.Control) { modifiers = modifiers | SystemWideHotKey.MOD_CONTROL; } if ((_inKey & Keys.Shift) == Keys.Shift) { modifiers = modifiers | SystemWideHotKey.MOD_SHIFT; } Keys k = _inKey & ~Keys.Control & ~Keys.Shift & ~Keys.Alt; DelegateFunction DelegMethod = delegate() { keyId = _inForm.GetHashCode(); RegisterHotKey((IntPtr)_inForm.Handle, keyId, modifiers, (int)k); }; _inForm.Invoke(DelegMethod); }
/// <summary> /// 实现方法体 /// </summary> /// <param name="source"></param> /// <param name="e"></param> private void timingEventImplement(object source, System.Timers.ElapsedEventArgs e) { DelegateFunction s = delegate() { sendMsgToStatus(message); switch (Tagmodel) { case "0": { writeFile(Application.StartupPath + @"\Cache\pycode-temp.code", codebox.Text); } break; case "as": { writeFile(SaveFileName, codebox.Text); } break; case "read": { writeFile(OpenFileName, codebox.Text); } break; } }; this.Invoke(s); }
private double CalculateOptimalStepSize(Function f, Vector currentPoint, Vector identity) { var g = new DelegateFunction(lambda => { return(f.Value(currentPoint.Select((xi, i) => xi + lambda[0] * identity[i]).ToArray())); }); // // Find the upper interval for the golden section line search // var upper = INITIAL_GOLDEN_SECTION_INTERVAL; // var lower = -upper; // var functionValue = f.Value(currentPoint.AsArray()); // // Double s until f(x + lambda*identity) > f(x) // while (f.Value(currentPoint.Select((xi, i) => xi + upper*identity[i]).ToArray()) <= functionValue) // { // upper *= 2; // } // // Double s until f(x - lambda*identity) > f(x) // while (f.Value(currentPoint.Select((xi, i) => xi + lower*identity[i]).ToArray()) <= functionValue) // { // lower *= 2; // } var minimizer = new GoldenSectionMinimizer(); minimizer.IsOutputEnabled = false; // return minimizer.Minimize(g, new GoldenSectionSearch.Interval(lower, upper)); return(minimizer.Minimize(g, 0)); }
/// <summary> /// 注册 /// </summary> /// <param name="callback"></param> public void RegistCallback(DelegateFunction <T> callback) { if (!m_callbacks.Contains(callback)) { m_callbacks.Add(callback); } }
/// <summary> /// 取消注册 /// </summary> /// <param name="callback"></param> public void UnRegistCallback(DelegateFunction <T> callback) { if (m_callbacks.Contains(callback)) { m_callbacks.Remove(callback); } }
public Task <string> DelegateRequestAsync(string delegatee) { var @delegateFunction = new DelegateFunction(); @delegateFunction.Delegatee = delegatee; return(ContractHandler.SendRequestAsync(@delegateFunction)); }
public Task <TransactionReceipt> DelegateRequestAndWaitForReceiptAsync(string delegatee, CancellationTokenSource cancellationToken = null) { var @delegateFunction = new DelegateFunction(); @delegateFunction.Delegatee = delegatee; return(ContractHandler.SendRequestAndWaitForReceiptAsync(@delegateFunction, cancellationToken)); }
/// <summary> /// 控制台焦点到最后一行 /// </summary> public void consoleScrollToEndImplement() { DelegateFunction s = delegate() { console.ScrollToLine(console.LineCount); }; this.Invoke(s); }
/// <summary> /// 注销数据 /// </summary> virtual public void Destroy() { RecordSystem.UnRegistRecordCallback(m_recordName, this); m_recordName = string.Empty; m_data.Clear(); m_data = null; m_callFunction = null; }
/// <summary> /// 数据解析类构造方法 /// </summary> /// <param name="name">数据表名称</param> /// <param name="callFunction">数据发送改变回调</param> public RecordBase(string name, DelegateFunction callFunction) { m_recordName = name; m_callFunction = callFunction; m_data = new List <object>(); RecordSystem.RegistRecordCallback(name, this); }
public static void AddTriggerGameObject(GameObject go, DelegateFunction f) { EventTrigger trigger = go.AddComponent <EventTrigger> (); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerClick; entry.callback.AddListener((BaseEventData) => { f(); }); trigger.triggers.Add(entry); }
public void TestFunction() { ExecutionEnvironment e = new ExecutionEnvironment(); e.RegisterFunction("a", DelegateFunction.CreateDelegate(this, "Test")); e.RegisterFunction("b", DelegateFunction.CreateDelegate(this, "Test2")); DelegateFunction f = e.GetFunction("a"); DelegateFunction f1 = e.GetFunction("b"); Assert.AreEqual(f.Invoke(), "a"); Assert.AreEqual(f1.Invoke(2), 2); }
private double CalculateOptimalStepSize(Function f, double[] currentPoint, double[] currentOffset) { var g = new DelegateFunction(alpha => { return(f.Value(currentPoint.Select((d, i) => d - alpha[0] * currentOffset[i]).ToArray())); }); var minimizer = new GoldenSectionMinimizer(); minimizer.IsOutputEnabled = false; return(minimizer.Minimize(g, 0)); }
//设置进度条的Value private void SetPos(int ipos) { if (this.bar.InvokeRequired) { DelegateFunction df = new DelegateFunction(SetPos); this.Invoke(df, new object[] { ipos }); } else { bar.setWidth(stepLength * ipos); } }
public static void SaveFunc(string fileName, DelegateFunction Func, double a, double b, double step) { FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); while (a <= b) { bw.Write(Func(a)); a += step; } bw.Close(); fs.Close(); }
public static void UnregisterHotKey(Form _inForm) { try { DelegateFunction df = delegate() { UnregisterHotKey(_inForm.Handle, keyId); }; _inForm.Invoke(df); } catch { } }
void Update() { float t = Time.deltaTime; DelegateFunction f = dFunctions[(int)_function]; float step = 2f / resolution; for (int i = 0, z = 0; z < resolution; z++) { float v = (z + 0.5f) * step - 1f; for (int x = 0; x < resolution; x++, i++) { float u = (x + 0.5f) * step - 1f; points[i].localPosition = f(u, v, t); } } }
private delegate void DelegateFunction();//代理 void control() { if (this.trackBar1.InvokeRequired)//等待异步 { DelegateFunction df = new DelegateFunction(control); this.Invoke(df);//invoke送主线程 } else { div = this.trackBar1.Value; //分频 channel = (int)(this.numericUpDown1.Value); //通道 textBox1.Clear(); textBox1.AppendText(datarate.ToString()); //数据率 textBox2.Clear(); textBox2.AppendText(samplerate.ToString()); //采样率 } }
/// <summary> /// 构造函数 /// </summary> public UDPScan() { InitializeComponent(); //当前要扫描的IP地址 string HostName = Dns.GetHostName(); //得到主机名 IPHostEntry IpEntry = Dns.GetHostEntry(HostName); //得到主机IP int ii = 0; for (; ii < IpEntry.AddressList.Length; ii++) { if (IpEntry.AddressList[ii].AddressFamily == AddressFamily.InterNetwork) { break; } } tbipFrom.Text = IpEntry.AddressList[ii].ToString(); this.m_delegateFunction = new DelegateFunction(subFunctionUDP); this.but_delegate = new DelegateButton(but_Protect); }
void control1() { try { if (this.comboBox1.InvokeRequired)//等待异步 { DelegateFunction df = new DelegateFunction(control1); this.Invoke(df);//invoke送主线程 } else { channel = comboBox1.SelectedIndex + 1; //switch (comboBox1.SelectedIndex) //{ // case 0: // { // selecomindex = 1; // } // break; // case 1: // { // selecomindex = 20; // } // break; // case 2: // { // selecomindex = 50; // } // break; // case 3: // { // selecomindex = 100; // } // break; //} } } catch (Exception) { } }
//设置进度条的Value private void SetPos(int ipos, string con) { if (this.progressBar1.InvokeRequired) { DelegateFunction df = new DelegateFunction(SetPos); Thread.Sleep(500); this.BeginInvoke(df, new object[] { ipos, con }); } else { this.label5.Text = "已完成" + ipos.ToString() + "%"; this.progressBar1.Value = Convert.ToInt32(ipos); this.textBox1.AppendText(con + " \n"); if (ipos == 100) { this.label2.Text = "仪表数据已同步完成!"; this.textBox1.AppendText("已完成所有仪表数据的同步!"); } } }
public void ToA() { _function = A; }
public Task <TransactionReceipt> DelegateRequestAndWaitForReceiptAsync(DelegateFunction @delegateFunction, CancellationTokenSource cancellationToken = null) { return(ContractHandler.SendRequestAndWaitForReceiptAsync(@delegateFunction, cancellationToken)); }
public Task <string> DelegateRequestAsync(DelegateFunction @delegateFunction) { return(ContractHandler.SendRequestAsync(@delegateFunction)); }
public void ToA() { _function = A; }
public void ToB() { _function = B; }
public void End() { delegateFunction = MyEndDelegateFunction; }
public void ToB() { _function = B; }
public void Start() { delegateFunction = MyDelegateFunction; boolDelegateFunction = MyBoolDelegateFunction; }