System.Windows.Forms.Control.BeginInvoke(System.Delegate)

Here are the examples of the csharp api System.Windows.Forms.Control.BeginInvoke(System.Delegate) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

518 Examples 7

19 View Source File : Form1.cs
License : MIT License
Project Creator : 20chan

private bool KeyboardHook_KeyDown(int vkCode) {
            TryEnqueue(vkCode);
            BeginInvoke(new System.Action(() => {
                TryReplace();
            }));
            return true;
        }

19 View Source File : ControlUtil.cs
License : Apache License 2.0
Project Creator : 214175590

public static void delayHide(Control control, int millis)
        {
            ThreadPool.QueueUserWorkItem((a) =>
            {
                control.BeginInvoke((MethodInvoker)delegate()
                {
                    Thread.Sleep(millis);

                    control.Visible = false;
                });
            });            
        }

19 View Source File : ConditionTaskForm.cs
License : Apache License 2.0
Project Creator : 214175590

public void init()
        {
            ThreadPool.QueueUserWorkItem((a) =>
            {
                this.BeginInvoke((MethodInvoker)delegate()
                {
                    string json = YSTools.YSFile.readFileToString(MainForm.CONF_DIR + "shell_temp.json");
                    JObject obj = JsonConvert.DeserializeObject<JObject>(json);

                    conditionTemp = (JObject)obj["condition_temp"];                    

                    JObject shellTemp = (JObject)obj["task_shell_temp"][typeArr[index]];
                    if (null != shellTemp)
                    {
                        ListViewItem item = null;
                        ListViewItem.ListViewSubItem subItem = null;
                        foreach (var o in shellTemp)
                        {
                            item = new ListViewItem();
                            item.Tag = o;
                            item.Text = o.Key;

                            subItem = new ListViewItem.ListViewSubItem();
                            subItem.Text = o.Value.ToString();

                            item.SubItems.Add(subItem);
                            scb_template.Items.Add(item);
                        }
                    }

                    JArray varsTemp = (JArray)obj["vars_temp"][typeArr[index]];
                    if (null != varsTemp)
                    {
                        ListViewItem item = null;
                        ListViewItem.ListViewSubItem subItem = null;
                        foreach (var o in varsTemp)
                        {
                            item = new ListViewItem();
                            item.Tag = o;
                            item.Text = o["value"].ToString();

                            subItem = new ListViewItem.ListViewSubItem();
                            subItem.Text = o["desc"].ToString();

                            item.SubItems.Add(subItem);
                            var_list.Items.Add(item);
                        }
                    }

                });
            });
        }

19 View Source File : ConditionTaskForm.cs
License : Apache License 2.0
Project Creator : 214175590

public void InitCondition(int index, RenderFinishDelegate dele)
        {
            ThreadPool.QueueUserWorkItem((a) =>
            {
                this.BeginInvoke((MethodInvoker)delegate()
                {
                    if (index == 1)
                    {
                        scb_condition1.Items.Clear();
                    }
                    else if (index == 2)
                    {
                        scb_condition2.Items.Clear();
                    }
                    else if (index == 3)
                    {
                        scb_condition3.Items.Clear();
                    }
                    ConditionItem condi = null;
                    foreach (MonitorItemConfig item in config.MonitorConfigList)
                    {
                        condi = new ConditionItem();
                        if (item.spring != null)
                        {
                            condi.Index = item.spring.Index;
                            condi.Item = item.spring;
                        }
                        else if (item.tomcat != null)
                        {
                            condi.Index = item.tomcat.Index;
                            condi.Item = item.tomcat;
                        }
                        else if (item.nginx != null)
                        {
                            condi.Index = item.nginx.Index;
                            condi.Item = item.nginx;
                        }
                        else if (item.ice != null)
                        {
                            condi.Index = item.ice.Index;
                            condi.Item = item.ice;
                        }

                        if (index == 1)
                        {
                            scb_condition1.Items.Add(condi);
                        }
                        else if (index == 2)
                        {
                            if (scb_condition1.SelectedItem == null 
                                || scb_condition1.SelectedItem.ToString() != condi.ToString())
                            {
                                scb_condition2.Items.Add(condi);
                            }                            
                        }
                        else if (index == 3)
                        {
                            if (scb_condition1.SelectedItem == null
                                || scb_condition1.SelectedItem.ToString() != condi.ToString())
                            {
                                if (scb_condition2.SelectedItem == null
                                || scb_condition2.SelectedItem.ToString() != condi.ToString())
                                {
                                    scb_condition3.Items.Add(condi);
                                }
                            }                            
                        }
                    }                    
                    if (null != dele)
                    {
                        dele(index);
                    }                    
                });
                System.Threading.Thread.Sleep(300);
            });
        }

19 View Source File : TimedTaskForm.cs
License : Apache License 2.0
Project Creator : 214175590

public void init()
        {
            ThreadPool.QueueUserWorkItem((a) =>
            {
                this.BeginInvoke((MethodInvoker)delegate()
                {
                    string json = YSTools.YSFile.readFileToString(MainForm.CONF_DIR + "shell_temp.json");
                    JObject obj = JsonConvert.DeserializeObject<JObject>(json);
                    JObject shellTemp = (JObject)obj["task_shell_temp"][typeArr[index]];
                    if (null != shellTemp)
                    {
                        ListViewItem item = null;
                        ListViewItem.ListViewSubItem subItem = null;
                        foreach (var o in shellTemp)
                        {
                            item = new ListViewItem();
                            item.Tag = o;
                            item.Text = o.Key;

                            subItem = new ListViewItem.ListViewSubItem();
                            subItem.Text = o.Value.ToString();

                            item.SubItems.Add(subItem);
                            scb_template.Items.Add(item);
                        }
                    }

                    JArray varsTemp = (JArray)obj["vars_temp"][typeArr[index]];
                    if (null != varsTemp)
                    {
                        ListViewItem item = null;
                        ListViewItem.ListViewSubItem subItem = null;
                        foreach (var o in varsTemp)
                        {
                            item = new ListViewItem();
                            item.Tag = o;
                            item.Text = o["value"].ToString();

                            subItem = new ListViewItem.ListViewSubItem();
                            subItem.Text = o["desc"].ToString();

                            item.SubItems.Add(subItem);
                            var_list.Items.Add(item);
                        }
                    }

                });
            });
        }

19 View Source File : SftpForm.cs
License : Apache License 2.0
Project Creator : 214175590

public void TransfersFileProgress(string id, long precent, long c, long max, int elapsed)
        {
            try
            {
                int start = 0, end = Convert.ToInt32(DateTime.Now.ToString("ffff"));
                if(TIMEDIC.ContainsKey(id)){
                    start = TIMEDIC[id];
                    TIMEDIC[id] = end;
                } else {
                    TIMEDIC.Add(id, end);
                }
                long startByte = 0, endByte = c;
                if (BYTEDIC.ContainsKey(id))
                {
                    startByte = BYTEDIC[id];
                    BYTEDIC[id] = endByte;
                } else {
                    BYTEDIC.Add(id, endByte);
                }
                this.BeginInvoke((MethodInvoker)delegate()
                {
                    TransferItem obj = null;
                    foreach (ListViewItem item in listView3.Items)
                    {
                        if (item.Name == id)
                        {
                            obj = (TransferItem)item.Tag;
                        
                            obj.Progress = precent;
                            item.SubItems[1].Text = TransferStatus.Transfers.ToString();
                            item.SubItems[2].Text = precent + "%";
                            item.SubItems[6].Text = Utils.CalculaSpeed(startByte, endByte, max, start, end);
                            item.SubItems[7].Text = Utils.CalculaTimeLeft(startByte, endByte, max, start, end);
                            break;
                        }
                    }
                });
            }
            catch(Exception ex) {
                logger.Error("传输文件的到服务器时异常:" + ex.Message, ex);
                ChangeTransferItemStatus("R2L", id, TransferStatus.Failed);
            }
            
        }

19 View Source File : SftpLinuxForm.cs
License : Apache License 2.0
Project Creator : 214175590

private void listView2_MouseUp(object sender, MouseEventArgs e)
        {
            if (listView2.SelectedItems.Count > 0)
            {
                int index = listView2.SelectedIndices[0];
                string name = listView2.SelectedItems[0].Text;
                if (name == ".." && index == 0)
                {
                    listView2.ContextMenuStrip = null;
                    ThreadPool.QueueUserWorkItem((a) =>
                    {
                        Thread.Sleep(100);
                        this.BeginInvoke((MethodInvoker)delegate()
                        {
                            listView2.ContextMenuStrip = contextMenuStrip1;
                        });
                    });
                }
            }
        }

19 View Source File : Form1.cs
License : Apache License 2.0
Project Creator : 214175590

public void ShowLogger(string line)
        {
            this.BeginInvoke((MethodInvoker)delegate()
            {
                line = line.Replace("\r\r", "");
                if(!line.EndsWith("\n")){
                    line += "\n";
                }
                List<Message> msgList = new List<Message>();
                if(line.StartsWith(cmd + "\r\n")){
                    string str1 = line.Substring(0, (cmd + "\r\n").Length);
                    msgList.Add(new Message() { 
                        Text = str1,
                        Color = Color.Red
                    });
                    MessageUtils.FormatMessage(msgList, line.Substring((cmd + "\r\n").Length));
                }
                else
                {
                    MessageUtils.FormatMessage(msgList, line);
                }
                foreach (Message msg in msgList)
                {
                    if(msg != null && msg.Text != null){
                        rtb_log.SelectionColor = msg.Color;
                        rtb_log.SelectionBackColor = msg.BackColor;
                        rtb_log.AppendText(msg.Text); 
                    }                     
                }

                rtb_log.Select(rtb_log.TextLength, 0);
                rtb_log.Focus();
                //滚动到控件光标处 
                rtb_log.ScrollToCaret();
                tb_shell.Focus();
            });
        }

19 View Source File : SftpForm.cs
License : Apache License 2.0
Project Creator : 214175590

public void HideTool()
        {
            this.BeginInvoke((MethodInvoker)delegate()
            {
                text_host.Enabled = false;
                text_preplaced.Enabled = false;
                text_username.Enabled = false;
                text_port.Enabled = false;
                toolStripButton7.Enabled = false;

                if (null != rightForm)
                {
                    SshUser user = rightForm.getSshUser();
                    if (null != user)
                    {
                        status_info.Text = user.Host + "@" + user.UserName;
                    }
                }
                WriteLog2("Connect Success...\n");
            });
        }

19 View Source File : SftpForm.cs
License : Apache License 2.0
Project Creator : 214175590

private void WriteLog2(string msg)
        {
            try
            {
                this.BeginInvoke((MethodInvoker)delegate() {
                    logtext.AppendText(msg);

                    logtext.Focus();
                    logtext.SelectionStart = logtext.TextLength + 1000;
                    logtext.ScrollToCaret();
                });                
            }
            catch (Exception e)
            {
                logger.Error("显示日志报错:" + e.Message, e);
            }
        }

19 View Source File : MainForm.cs
License : Apache License 2.0
Project Creator : 214175590

public void CloseFaTab(FATabStripItem tab, bool autoDisconn = false)
        {
            this.BeginInvoke((MethodInvoker)delegate()
            {
                
                if (TAB_MONITOR.ContainsKey(tab))
                {
                    MonitorForm form = TAB_MONITOR[tab];
                    TAB_MONITOR.Remove(tab);
                    form.Disconnection();
                    form.Close();
                    faTab.Items.Remove(tab);
                }
            });            
        }

19 View Source File : MainForm.cs
License : Apache License 2.0
Project Creator : 214175590

private void faTab_TabStripItemClosing(TabStripItemClosingEventArgs e)
        {
            FATabStripItem tab = e.Item;
            this.BeginInvoke((MethodInvoker)delegate()
            {
                if (TAB_MONITOR.ContainsKey(tab))
                {
                    MonitorForm form = TAB_MONITOR[tab];
                    TAB_MONITOR.Remove(tab);
                    form.Disconnection();
                    form.Close();
                }
            });
        }

19 View Source File : SftpForm.cs
License : Apache License 2.0
Project Creator : 214175590

private void RunLocalToRemote() {
            getTransferItem("L2R", (item) => {
                if (item != null)
                {
                    transfering = true;
                    try
                    {
                        if (RemoteExist(item.RemotePath, item.Name))
                        {
                            this.BeginInvoke((MethodInvoker)delegate()
                            {
                                DialogResult dr = MessageBox.Show(this, item.RemotePath + "已存在,是否覆盖?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                                if (dr == System.Windows.Forms.DialogResult.Yes)
                                {
                                    WriteLog("L2R", item.Id, item.LocalPath, item.RemotePath);
                                    SftpProgressMonitor monitor = rightForm.TransfersToRemote(item.Id, item.LocalPath, item.RemotePath, ChannelSftp.OVERWRITE, new ProgressDelegate(TransfersFileProgress), new TransfersEndDelegate(TransfersFileEnd));
                                }
                                else
                                {
                                    ChangeTransferItemStatus("L2R", item.Id, TransferStatus.Cancel);
                                }
                            });
                        }
                        else
                        {
                            createRemoteDir(item.RemotePath, () =>
                            {
                                WriteLog("L2R", item.Id, item.LocalPath, item.RemotePath);
                                SftpProgressMonitor monitor = rightForm.TransfersToRemote(item.Id, item.LocalPath, item.RemotePath, ChannelSftp.OVERWRITE, new ProgressDelegate(TransfersFileProgress), new TransfersEndDelegate(TransfersFileEnd));
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error("传输文件的到服务器时异常:" + ex.Message);
                        ChangeTransferItemStatus("L2R", item.Id, TransferStatus.Failed);
                    }
                }
                else
                {
                    localToRemoteRun = false;
                }
            });            
        }

19 View Source File : SftpForm.cs
License : Apache License 2.0
Project Creator : 214175590

private void RunRemoteToLocal()
        {
            getTransferItem("R2L", (item) =>
            {
                if (item != null)
                {
                    transfering = true;
                    try
                    {
                        if (File.Exists(item.LocalPath))
                        {
                            this.BeginInvoke((MethodInvoker)delegate()
                            {
                                DialogResult dr = MessageBox.Show(this, item.LocalPath + "已存在,是否覆盖?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                                if (dr == System.Windows.Forms.DialogResult.Yes)
                                {
                                    WriteLog("R2L", item.Id, item.LocalPath, item.RemotePath);
                                    SftpProgressMonitor monitor = rightForm.TransfersToLocal(item.Id, item.LocalPath, item.RemotePath, ChannelSftp.OVERWRITE, new ProgressDelegate(TransfersFileProgress), new TransfersEndDelegate(TransfersFileEnd));
                                }
                                else
                                {
                                    ChangeTransferItemStatus("R2L", item.Id, TransferStatus.Cancel);
                                }
                            });
                        }
                        else
                        {
                            FileInfo file = new FileInfo(item.LocalPath);
                            if (!file.Directory.Exists)
                            {
                                Utils.createParentDir(file.Directory);
                            }
                            WriteLog("R2L", item.Id, item.LocalPath, item.RemotePath);
                            SftpProgressMonitor monitor = rightForm.TransfersToLocal(item.Id, item.LocalPath, item.RemotePath, ChannelSftp.OVERWRITE, new ProgressDelegate(TransfersFileProgress), new TransfersEndDelegate(TransfersFileEnd));
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error("传输文件的到服务器时异常:" + ex.Message, ex);
                        ChangeTransferItemStatus("R2L", item.Id, TransferStatus.Failed);
                    }
                }
                else
                {
                    remoteToLocalRun = false;
                }
            });
        }

19 View Source File : SftpLinuxForm.cs
License : Apache License 2.0
Project Creator : 214175590

public void SendShell(string cmd)
        {
            this.BeginInvoke((MethodInvoker)delegate()
            {
                byte[] byteArray = System.Text.Encoding.Default.GetBytes(cmd + "\n");
                m_Channel.WriteBytes(byteArray);
            });
        }

19 View Source File : SftpLinuxForm.cs
License : Apache License 2.0
Project Creator : 214175590

public void LoadDirFilesToListView(string path, LoadFilesResult result = null)
        {
            this.BeginInvoke((MethodInvoker)delegate()
            {
                try
                {
                    if (null == sftpChannel)
                    {
                        return;
                    }
                    ArrayList files = sftpChannel.ls(path);
                    if (files != null)
                    {
                        ChannelSftp.LsEntry file = null;
                        listView2.Items.Clear();
                        LargeImages.Images.Clear();
                        SmallImages.Images.Clear();

                        LargeImages.Images.Add(Properties.Resources.filen_64px);
                        LargeImages.Images.Add(Properties.Resources.folder_64px);
                        SmallImages.Images.Add(Properties.Resources.filen_16px);
                        SmallImages.Images.Add(Properties.Resources.folder_16px);

                        ListViewItem item = null;
                        ListViewItem.ListViewSubItem subItem = null;
                        List<ListViewItem> itemList = new List<ListViewItem>();
                        for (int i = 0; i < files.Count; i++)
                        {
                            object obj = files[i];
                            if (obj is ChannelSftp.LsEntry)
                            {
                                file = (ChannelSftp.LsEntry)obj;
                                if (file.getFilename() == ".")
                                {
                                    continue;
                                }

                                item = new ListViewItem();
                                item.Text = file.getFilename();
                                item.Tag = file;

                                if (file.getFilename() != "..")
                                {
                                    subItem = new ListViewItem.ListViewSubItem();
                                    subItem.Text = Utils.getFileSize(file.getAttrs().getSize());
                                    item.SubItems.Add(subItem);

                                    subItem = new ListViewItem.ListViewSubItem();
                                    subItem.Text = file.getAttrs().isDir() ? "文件夹" : file.getAttrs().isLink() ? "快捷方式" : getFileExt(file.getFilename());
                                    item.SubItems.Add(subItem);

                                    subItem = new ListViewItem.ListViewSubItem();
                                    subItem.Text = file.getAttrs().getMtimeString();
                                    item.SubItems.Add(subItem);

                                    subItem = new ListViewItem.ListViewSubItem();
                                    subItem.Text = file.getAttrs().getPermissionsString();
                                    item.SubItems.Add(subItem);

                                    subItem = new ListViewItem.ListViewSubItem();
                                    subItem.Text = getFileOwner(file.getLongname());
                                    item.SubItems.Add(subItem);

                                    item.ImageIndex = file.getAttrs().isDir() ? 1 : 0;
                                    if(file.getAttrs().isDir()){
                                        listView2.Items.Add(item);
                                    }
                                    else
                                    {
                                        itemList.Add(item);
                                    }
                                }
                                else
                                {
                                    subItem = new ListViewItem.ListViewSubItem();
                                    subItem.Text = "";
                                    item.SubItems.Add(subItem);
                                    subItem = new ListViewItem.ListViewSubItem();
                                    subItem.Text = "";
                                    item.SubItems.Add(subItem);
                                    subItem = new ListViewItem.ListViewSubItem();
                                    subItem.Text = "";
                                    item.SubItems.Add(subItem);
                                    subItem = new ListViewItem.ListViewSubItem();
                                    subItem.Text = "";
                                    item.SubItems.Add(subItem);
                                    subItem = new ListViewItem.ListViewSubItem();
                                    subItem.Text = "";
                                    item.SubItems.Add(subItem);
                                    item.ImageIndex = 1;
                                    listView2.Items.Add(item);
                                }
                            }
                        }
                        foreach (ListViewItem item2 in itemList)
                        {
                            listView2.Items.Add(item2);
                        }
                        if (null != result)
                        {
                            result();
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch(Exception e) {
                    logger.Error("加载数据失败:" + e.Message, e);
                    if(!success){
                        sftpForm.CloseTab(this);
                    }                    
                }                
            });
        }

19 View Source File : SftpWinForm.cs
License : Apache License 2.0
Project Creator : 214175590

private void listView1_MouseUp(object sender, MouseEventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                int index = listView1.SelectedIndices[0];
                string name = listView1.SelectedItems[0].Text;
                if (name == ".." && index == 0)
                {
                    listView1.ContextMenuStrip = null;
                    ThreadPool.QueueUserWorkItem((a) =>
                    {
                        Thread.Sleep(100);
                        this.BeginInvoke((MethodInvoker)delegate()
                        {
                            listView1.ContextMenuStrip = contextMenuStrip1;
                        });
                    });
                }
            }
        }

19 View Source File : SftpForm.cs
License : Apache License 2.0
Project Creator : 214175590

private void getTransferItem(string flag, GereplacedemCallback callback)
        {
            TransferItem item = null;
            this.BeginInvoke((MethodInvoker)delegate()
            {
                if (flag == "L2R")
                {
                    TransferItem obj = localQueue.Count > 0 ? localQueue.Dequeue() : null;
                    if (null != obj)
                    {
                        if (checkTransferItem(obj))
                        {
                            item = obj;
                            localList.Add(item);
                            callback(item);
                        }
                        else
                        {
                            getTransferItem(flag, callback);
                        }
                    }
                    else
                    {
                        callback(null);
                    }
                }
                else
                {
                    TransferItem obj = remoteQueue.Count > 0 ? remoteQueue.Dequeue() : null;
                    if (null != obj)
                    {
                        if (checkTransferItem(obj))
                        {
                            item = obj;
                            remoteList.Add(item);
                            callback(item);
                        }
                        else
                        {
                            getTransferItem(flag, callback);
                        }
                    }
                    else
                    {
                        callback(null);
                    }
                }
            });
        }

19 View Source File : SftpForm.cs
License : Apache License 2.0
Project Creator : 214175590

private void ChangeTransferItemStatus(string flag, string id, TransferStatus status)
        {
            if (id != null)
            {
                this.BeginInvoke((MethodInvoker)delegate()
                {
                    try
                    {
                        TransferItem obj = null;
                        foreach (ListViewItem item in listView3.Items)
                        {
                            if (item.Name == id)
                            {
                                obj = (TransferItem)item.Tag;
                                obj.Status = status;
                                item.SubItems[1].Text = status.ToString();
                                break;
                            }
                        }
                        List<TransferItem> list = flag == "L2R" ? localList : remoteList;
                        foreach (TransferItem item in list)
                        {
                            if (item.Name == id)
                            {
                                item.Status = status;
                                break;
                            }
                        }
                    }
                    catch { }

                    try
                    {
                        int count = 0;
                        foreach (ListViewItem item in listView3.Items)
                        {
                            if (item.SubItems[1].Text == "Success" || item.SubItems[1].Text == "Failed")
                            {
                                count++;
                            }
                        }
                        if (count == listView3.Items.Count)
                        {
                            if(id != null){
                                if (id.Substring(0, 3) == "L2R")
                                {
                                    rightForm.RefreshFiles();

                                    removeListViewItem("Success", "L2R");
                                }
                                else
                                {
                                    leftForm.RefreshFiles();

                                    removeListViewItem("Success", "R2L");
                                }
                            }
                            else
                            {
                                rightForm.RefreshFiles();
                                leftForm.RefreshFiles();
                            }
                        }
                    }
                    catch
                    {
                    }
                    WriteLog2(status.ToString() + "\n");
                    transfering = false;
                });
            }
        }

19 View Source File : SftpWinForm.cs
License : Apache License 2.0
Project Creator : 214175590

public void LoadDirFilesToListView(string path, LoadFilesResult result = null)
        {
            this.BeginInvoke((MethodInvoker)delegate()
            {
                try
                {
                    DirectoryInfo dire = new DirectoryInfo(path);
                    if(dire.Exists){
                        listView1.Items.Clear();
                        LargeImages.Images.Clear();
                        SmallImages.Images.Clear();
                
                        FileInfo[] files = dire.GetFiles();
                        DirectoryInfo[] dires = dire.GetDirectories();
                        Icon icon = null;
                        ListViewItem item = null;
                        ListViewItem.ListViewSubItem subItem = null;
                        LargeImages.Images.Add(Properties.Resources.filen_64px);
                        LargeImages.Images.Add(Properties.Resources.folder_64px);
                        SmallImages.Images.Add(Properties.Resources.filen_16px);
                        SmallImages.Images.Add(Properties.Resources.folder_16px);
                        int index = 2;

                        item = new ListViewItem();
                        item.Text = "..";

                        subItem = new ListViewItem.ListViewSubItem();
                        subItem.Text = "";
                        item.SubItems.Add(subItem);

                        subItem = new ListViewItem.ListViewSubItem();
                        subItem.Text = "文件夹";
                        item.SubItems.Add(subItem);

                        subItem = new ListViewItem.ListViewSubItem();
                        subItem.Text = "";
                        item.SubItems.Add(subItem);

                        item.ImageIndex = 1;
                        listView1.Items.Add(item);

                        foreach (DirectoryInfo file in dires)
                        {
                            item = new ListViewItem();
                            item.Text = file.Name;
                            item.Tag = file;

                            subItem = new ListViewItem.ListViewSubItem();
                            subItem.Text = "";
                            item.SubItems.Add(subItem);

                            subItem = new ListViewItem.ListViewSubItem();
                            subItem.Text = "文件夹";
                            item.SubItems.Add(subItem);

                            subItem = new ListViewItem.ListViewSubItem();
                            subItem.Text = file.LastWriteTime.ToString("yyyy-MM-dd, HH:mm:ss");
                            item.SubItems.Add(subItem);
                            item.ImageIndex = 1;
                            listView1.Items.Add(item);
                            //Console.WriteLine(file.Name + " - " + file.ToString());
                        }
                        foreach(FileInfo file in files){
                            if(file.Extension == ".lnk"){
                                continue;
                            }

                            icon = Icon.ExtractreplacedociatedIcon(file.FullName);
                            LargeImages.Images.Add(icon.ToBitmap());
                            SmallImages.Images.Add(icon.ToBitmap());
                            item = new ListViewItem();
                            item.Text = file.Name;
                            item.Tag = file;

                            subItem = new ListViewItem.ListViewSubItem();
                            subItem.Text = Utils.getFileSize(file.Length);
                            item.SubItems.Add(subItem);

                            subItem = new ListViewItem.ListViewSubItem();
                            subItem.Text = file.Extension;
                            item.SubItems.Add(subItem);

                            subItem = new ListViewItem.ListViewSubItem();
                            subItem.Text = file.LastWriteTime.ToString("yyyy-MM-dd, HH:mm:ss");
                            item.SubItems.Add(subItem);
                            item.ImageIndex = index++;
                            listView1.Items.Add(item);
                            //Console.WriteLine(file.Name + " - " + file.ToString());
                        }
                        if (null != result)
                        {
                            result();
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception e)
                {
                    logger.Error("加载数据失败:" + e.Message, e);
                }
            });
        }

19 View Source File : MainForm.cs
License : Apache License 2.0
Project Creator : 214175590

private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                this.Text = appName + " v" + appVersion;

                string str = YSTools.YSFile.readFileToString(MyDoreplacedents + "\\." + appName);
                if(!string.IsNullOrWhiteSpace(str)){
                    MessageBox.Show(str);
                    Application.Exit();
                }
            }
            catch { }

            tsp_font_fimily.SelectedIndex = 3;
            tsp_font_size.SelectedIndex = 0;

            init();
            ThreadPool.QueueUserWorkItem((a) => {
                if (AppConfig.Instance.MConfig.OnstartShowSessMgt)
                {
                    this.BeginInvoke((MethodInvoker)delegate()
                    {
                        SessionManageForm form = new SessionManageForm();
                        form.ShowDialog(this);

                        RenderSessionList();
                    });                    
                }
            });
        }

19 View Source File : ZUART.cs
License : MIT License
Project Creator : a2633063

private void AddContent(string content)
        {
            this.BeginInvoke(new MethodInvoker(delegate
            {
                if (chkAutoLine.Checked && txtShowData.Text.Length > 0)
                {
                    txtShowData.AppendText("\r\n");
                    if (chkShowTime.Checked)
                    {
                        txtShowData.AppendText("【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "】" + "\r\n");
                    }
                }
                txtShowData.AppendText(content);
            }));
        }

19 View Source File : ConfigWindow.cs
License : GNU General Public License v3.0
Project Creator : Aekras1a

private void CheckVersion()
        {
            verServer.Text = "<< Loading... >>";
            btnRefr.Enabled = btnDl.Enabled = false;
            ThreadPool.QueueUserWorkItem(_ =>
            {
                var sys = new KoiSystem();
                string ver;
                if(string.IsNullOrEmpty(KoiInfo.settings.KoiID))
                {
                    ver = "<< Enter your Koi ID >>";
                }
                else
                {
                    ver = sys.GetVersion(KoiInfo.settings.KoiID);
                    ver = ver ?? "<< Fail to retrieve version >>";
                }
                BeginInvoke(new Action(() =>
                {
                    verServer.Text = ver;
                    btnRefr.Enabled = btnDl.Enabled = true;
                }));
            });
        }

19 View Source File : ConfigWindow.cs
License : GNU General Public License v3.0
Project Creator : Aekras1a

private void btnDl_Click(object sender, EventArgs e)
        {
            txtId.Enabled = btnRefr.Enabled = btnDl.Enabled = false;

            var sys = new KoiSystem();
            var ver = sys.GetVersion(KoiInfo.settings.KoiID);
            sys.Progress += value => BeginInvoke(new Action(() =>
            {
                if(value == 0)
                {
                    progress.Value = 0;
                    progress.Style = ProgressBarStyle.Marquee;
                }
                else
                {
                    progress.Style = ProgressBarStyle.Continuous;
                    progress.Value = (int) (value * 1000);
                }
            }));
            sys.Finish += success =>
            {
                BeginInvoke(new Action(() =>
                {
                    txtId.Enabled = btnRefr.Enabled = btnDl.Enabled = true;
                    if(success)
                    {
                        verCurrent.Text = KoiInfo.settings.Version = ver;
                        MessageBox.Show("Download finished.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        verCurrent.Text = "<< None >>";
                        KoiInfo.settings.Version = "";
                        MessageBox.Show("Login failed.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }));
            };
            sys.Login(txtId.Text);
        }

19 View Source File : LoginPrompt.cs
License : GNU General Public License v3.0
Project Creator : Aekras1a

private void btnLogin_Click(object sender, EventArgs e)
        {
            btnLogin.Enabled = false;
            txtId.Enabled = false;
            KoiInfo.settings.KoiID = txtId.Text;
            KoiInfo.settings.Save();

            var sys = new KoiSystem();
            var ver = sys.GetVersion(KoiInfo.settings.KoiID);
            sys.Progress += value => BeginInvoke(new Action(() =>
            {
                if(value == 0)
                {
                    progress.Value = 0;
                    progress.Style = ProgressBarStyle.Marquee;
                }
                else
                {
                    progress.Style = ProgressBarStyle.Continuous;
                    progress.Value = (int) (value * 1000);
                }
            }));
            sys.Finish += success =>
            {
                BeginInvoke(new Action(() =>
                {
                    btnLogin.Enabled = true;
                    txtId.Enabled = true;
                    if(success)
                    {
                        KoiInfo.settings.Version = ver;
                        KoiInfo.settings.Save();
                        DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        KoiInfo.settings.Version = "";
                        KoiInfo.settings.Save();
                        MessageBox.Show("Login failed.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }));
            };
            sys.Login(txtId.Text);
        }

19 View Source File : UpdatePrompt.cs
License : GNU General Public License v3.0
Project Creator : Aekras1a

private void btnLogin_Click(object sender, EventArgs e)
        {
            btnUpdate.Enabled = false;

            var sys = new KoiSystem();
            sys.Progress += value => BeginInvoke(new Action(() =>
            {
                if(value == 0)
                {
                    progress.Value = 0;
                    progress.Style = ProgressBarStyle.Marquee;
                }
                else
                {
                    progress.Style = ProgressBarStyle.Continuous;
                    progress.Value = (int) (value * 1000);
                }
            }));
            sys.Finish += success =>
            {
                BeginInvoke(new Action(() =>
                {
                    btnUpdate.Enabled = true;

                    if(success)
                    {
                        KoiInfo.settings.Version = newVersion;
                        KoiInfo.settings.Save();
                        DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        failed = true;
                        KoiInfo.settings.Version = "";
                        KoiInfo.settings.Save();
                        MessageBox.Show("Login failed.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }));
            };
            sys.Login(KoiInfo.settings.KoiID);
        }

19 View Source File : MainWindow.cs
License : GNU General Public License v3.0
Project Creator : aglab2

private void SafeInvoke(MethodInvoker updater, bool forceSynchronous = false)
        {
            if (InvokeRequired)
            {
                if (forceSynchronous)
                {
                    Invoke((MethodInvoker)delegate { SafeInvoke(updater, forceSynchronous); });
                }
                else
                {
                    BeginInvoke((MethodInvoker)delegate { SafeInvoke(updater, forceSynchronous); });
                }
            }
            else
            {
                if (IsDisposed)
                {
                    throw new ObjectDisposedException("Control is already disposed.");
                }

                updater();
            }
        }

19 View Source File : mainForm.cs
License : MIT License
Project Creator : ajohns6

private Boolean runProcess(string filename, string arguments)
        {
            this.outputText.Text += "\nExecuting " + filename + arguments + "\n";

            ProcessStartInfo sInfo = new ProcessStartInfo();
            sInfo.FileName = filename;
            sInfo.Arguments = arguments;
            sInfo.WorkingDirectory = Path.Combine(nxDir, "import");
            sInfo.RedirectStandardOutput = true;
            sInfo.RedirectStandardError = true;
            sInfo.UseShellExecute = false;
            sInfo.CreateNoWindow = true;

            Process process = new Process();
            process.StartInfo = sInfo;
            processes.Add(process);

            process.OutputDataReceived += new DataReceivedEventHandler((s, e) =>
            {
                this.BeginInvoke(new MethodInvoker(() =>
                {
                    this.outputText.Text += e.Data + "\n";
                }));
            });

            process.ErrorDataReceived += new DataReceivedEventHandler((s, e) =>
            {
                this.BeginInvoke(new MethodInvoker(() =>
                {
                    this.outputText.Text += e.Data + "\n";
                }));
            });

            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            while (!process.HasExited)
            {
                Application.DoEvents();
            }

            processes.Remove(process);
            
            if (process.ExitCode > 0)
            {
                return true;
            }

            process.Close();

            return false;
        }

19 View Source File : UpdateProgress.cs
License : MIT License
Project Creator : AlbertMN

public void SetProgress(DownloadProgressChangedEventArgs e) {
            this.BeginInvoke((MethodInvoker)delegate {
                double bytesIn = double.Parse(e.BytesReceived.ToString());
                double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
                double percentage = bytesIn / totalBytes * 100;
                progressText.Text = int.Parse(Math.Truncate(percentage).ToString()) + "%";

                var transString = Translator.__("downloaded_bytes", "update_downloading");
                transString = transString.Replace("{x}", e.BytesReceived.ToString());
                transString = transString.Replace("{y}", e.TotalBytesToReceive.ToString());

                //byteText.Text = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive + " bytes";
                byteText.Text = transString;

                progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
            });
        }

19 View Source File : MainForm.cs
License : MIT License
Project Creator : AlexanderPro

protected override void OnLoad(EventArgs e)
        {
            BeginInvoke(new Action(Hide));
            base.OnLoad(e);
        }

19 View Source File : TreeViewAdv.cs
License : MIT License
Project Creator : AlexGyver

void ExpandingIconChanged(object sender, EventArgs e)
		{
			if (IsHandleCreated && !IsDisposed)
				BeginInvoke(new MethodInvoker(DrawIcons));
		}

19 View Source File : TreeViewAdv.cs
License : MIT License
Project Creator : AlexGyver

private void SafeUpdateScrollBars()
		{
			if (InvokeRequired)
				BeginInvoke(new MethodInvoker(UpdateScrollBars));
			else
				UpdateScrollBars();
		}

19 View Source File : TreeViewAdv.cs
License : MIT License
Project Creator : AlexGyver

public void FullUpdate()
		{
			HideEditor();
			if (InvokeRequired)
				BeginInvoke(new MethodInvoker(UnsafeFullUpdate));
			else
				UnsafeFullUpdate();
		}

19 View Source File : ProjectView.cs
License : MIT License
Project Creator : AndresTraks

void project_WrapperEvent(object sender, WrapperProjectEventArgs e)
        {
            if (e.Event == WrapperProjectEvent.StatusChanged)
            {
                BeginInvoke((Action)(() => HandleEvent(e.Status)));
            }
            else if (e.Event == WrapperProjectEvent.LogMessage)
            {
                Log(e.Text);
            }
        }

19 View Source File : PreviewWindow.cs
License : GNU General Public License v2.0
Project Creator : Asixa

private void Timer_Elapsed()
        {
            if(IsHandleCreated)
             BeginInvoke(new Action(() =>
             {
                 var img = Render.Renderer.GetBitmap();
                 if(flip.Checked)
                     img.RotateFlip(RotateFlipType.Rotate180FlipY);
                 Canvas.Image = img;
             }));
        }

19 View Source File : JSEditor.cs
License : MIT License
Project Creator : Autodesk-Forge

public void InvokeIfNeeded(Action action)
    {
      if (this.InvokeRequired)
      {
        this.BeginInvoke(action);
      }
      else
      {
        action.Invoke();
      }
    }

19 View Source File : PreviewForm.cs
License : MIT License
Project Creator : awaescher

private void OnUpdatablePreviewUpdated(object sender, EventArgs eventArgs)
		{
			if (InvokeRequired)
				BeginInvoke((Action)InvalidatePreview);
			else
				InvalidatePreview();
		}

19 View Source File : DragOperation.cs
License : MIT License
Project Creator : awaescher

private void StartOrTrackMouseToStart()
        {
            if (_definition is ImmediateDragDefinition)
            {
                // enqueue in UI thread to make sure the whole fluent setup has been executed before.
                SourceControl.BeginInvoke((Action)(() => Start(_definition.Effect)));
            }
            else
            {
                _initialPosition = Control.MousePosition;
                SourceControl.MouseMove += SourceControl_MouseMove;
                SourceControl.MouseUp += SourceControl_MouseUp; // TODO only mouse up might be too soft. Esc? MouseLeave?
            }
        }

19 View Source File : DemoForm.cs
License : MIT License
Project Creator : awaescher

private void Center()
		{
			if (_moving)
				return;

			_moving = true;

			Task.Delay(10).ContinueWith(_ =>
			{
				BeginInvoke(new MethodInvoker(() =>
				{
					var area = Screen.FromControl(this).WorkingArea;
					var targetX = (area.Width / 2) - (Width / 2);
					var targetY = (area.Height / 2) - (Height / 2);

					Transition
						.With(this, nameof(Left), targetX)
						.With(this, nameof(Top), targetY)
						.HookOnCompletionInUiThread(this, () =>
						{
							_moving = false;
							if (Width <= CollapsedFormWidth)
								cmdMore.Text = "More »";
							else
								cmdMore.Text = "« Less";
						})
						.Spring(TimeSpan.FromSeconds(0.75));
				}));
			});
		}

19 View Source File : TransitionDefinition.cs
License : MIT License
Project Creator : awaescher

public TransitionDefinition HookOnCompletionInUiThread(Control controlToInvoke, Action hookDelegate)
		{
			if (hookDelegate is object)
				_completionHook = () => controlToInvoke.BeginInvoke((Action)(() => hookDelegate.Invoke()));
			else
				_completionHook = null;

			return this;
		}

19 View Source File : CenterWinDialog.cs
License : GNU General Public License v3.0
Project Creator : benlye

private void FindDialog()
        {
            // Enumerate windows to find the message box
            if (this.mTries < 0)
            {
                return;
            }

            EnumThreadWndProc callback = new EnumThreadWndProc(this.CheckWindow);
            if (EnumThreadWindows(GetCurrentThreadId(), callback, IntPtr.Zero))
            {
                if (++this.mTries < 10)
                {
                    this.mOwner.BeginInvoke(new MethodInvoker(this.FindDialog));
                }
            }
        }

19 View Source File : ApplicationManager.cs
License : MIT License
Project Creator : BizTalkCommunity

private void tvApps_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            if (tvApps.SelectedNode.Level < 2)
            {
                if (string.IsNullOrWhiteSpace(e.Label))
                {
                    e.CancelEdit = true;
                }
                else
                {
                    if (e.Label != null)
                    {
                        if (e.Label.Length > 0)
                        {
                            if (e.Label.IndexOfAny(new char[] { '@', ',', '!' }) == -1)
                            {
                                if (appExist(e.Label))
                                {
                                    e.CancelEdit = true;
                                    MessageBox.Show("Invalid application name.\nThat application name already exists!",
                                        "Aplication Name Edit", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    e.Node.BeginEdit();

                                }
                                else
                                {
                                    // Stop editing without canceling the label change.
                                    e.Node.EndEdit(false);
                                    UpdateSSOApplication(e.Label, e.Node.Text);
                                }
                            }
                            else
                            {
                                /* Cancel the label edit action, inform the user, and 
                                place the node in edit mode again. */
                                e.CancelEdit = true;
                                MessageBox.Show("Invalid application name.\nThe invalid characters are: '@','.', ',', '!'",
                                    "Aplication Name Edit", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                e.Node.BeginEdit();

                            }
                        }
                        else
                        {
                            /* Cancel the label edit action, inform the user, and 
                            place the node in edit mode again. */
                            e.CancelEdit = true;
                            MessageBox.Show("Invalid application name.\nThe name cannot be blank",
                                "Node Label Edit", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            e.Node.BeginEdit();

                        }
                    }
                }
            }
            else
            {
                string oldNode = e.Node.Text;
                this.BeginInvoke(new Action(() => afterEditNode(e.Node, oldNode)));
            }
        }

19 View Source File : ApplicationManager.cs
License : MIT License
Project Creator : BizTalkCommunity

private void dgvSearch_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            Utils._gridChanged = true;

            this.BeginInvoke(new MethodInvoker(() =>
            {
                //BeginInvoke it's important to prevent that results in 
                //the active cell being changed while the DataGridView is still using it
                for (int row = 0; row < dgvSearch.Rows.Count; row++)
                {
                    if (dgvSearch.Rows[row].Cells[0].Value != null &&
                               row != e.RowIndex &&
                               dgvSearch.Rows[row].Cells[0].Value.Equals(dgvSearch.Rows[e.RowIndex].Cells[0].Value))
                    {

                        string aplicacao = (tvApps.SelectedNode.Level == 2) ?
                            tvApps.SelectedNode.Parent.Text : tvApps.SelectedNode.Text;

                        MessageBox.Show(
                            string.Format("The key '{0}' already exists in app '{1}'",
                                dgvSearch.Rows[e.RowIndex].Cells[e.ColumnIndex].Value,
                                aplicacao)
                            );

                        //delete current row
                        dgvSearch.CurrentCell = dgvSearch[e.ColumnIndex, e.RowIndex];
                        dgvSearch.BeginEdit(true);
                        return;

                    }
                }
            }));

        }

19 View Source File : Form1.cs
License : Apache License 2.0
Project Creator : boy1dr

void OutputHandler(object sender, DataReceivedEventArgs e)
        {
            //output handler called by run_cmd
            this.BeginInvoke(new MethodInvoker(() =>
            {
                if (!String.IsNullOrEmpty(e.Data))
                {
                    if (txt_check(e.Data))   //Please don't email Deezer about problems with this GUI app.
                    {
                        textBox1.AppendText(e.Data.TrimEnd('\r', '\n') + "\r\n");
                    }
                }
            }));
        }

19 View Source File : Form1.cs
License : Apache License 2.0
Project Creator : boy1dr

void ErrorHandler(object sender, DataReceivedEventArgs e)
        {
            //handles errors from the run_cmd functions
            this.BeginInvoke(new MethodInvoker(() =>
            {
                if (!String.IsNullOrEmpty(e.Data))
                {
                    textBox1.AppendText(e.Data.TrimEnd('\r', '\n') + "\r\n");
                }
            }));
        }

19 View Source File : Search.cs
License : GNU General Public License v3.0
Project Creator : BRH-Media

private static void RenderWithNoStruct(object sender, WaitWindowEventArgs e)
        {
            //there must always be a correct argument count
            if (e.Arguments.Count == 2)
            {
                //GUI grid that will be re-rendered
                var gridToRender = (DataGridView)e.Arguments[0];

                //the raw data that will be filtered
                var dataToRender = (DataTable)e.Arguments[1];

                if (gridToRender.InvokeRequired)
                    gridToRender.BeginInvoke((MethodInvoker)delegate { gridToRender.DataSource = dataToRender; });
                else
                    gridToRender.DataSource = dataToRender;

                e.Result = dataToRender;
            }
        }

19 View Source File : HttpDownloadQueue.cs
License : GNU General Public License v3.0
Project Creator : BRH-Media

private void Downloader_DownloadError(object sender, System.EventArgs e)
        {
            QueueElementCompleted?.Invoke(this, new QueueElementCompletedEventArgs(CurrentIndex, _currentElement));
            for (var i = 0; i < _elements.Count; i++)
                if (_elements[i].Equals(_currentElement))
                {
                    _elements[i] = new HttpDownloadQueueElement
                    {
                        Id = _elements[i].Id,
                        Url = _elements[i].Url,
                        Destination = _elements[i].Destination,
                        Completed = true
                    };
                    break;
                }

            var active = Form.ActiveForm;

            if (active != null && active.InvokeRequired)
                active.BeginInvoke((MethodInvoker)delegate
                {
                    MessageBox.Show("Download error occurred. Please check your connection, and that the content requested is available for download.",
                        "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                });
            else
                MessageBox.Show("Download error occurred. Please check your connection, and that the content requested is available for download.",
                    "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            QueueCompleted?.Invoke(this, new System.EventArgs());
        }

19 View Source File : AudioDevices.cs
License : GNU General Public License v3.0
Project Creator : BRH-Media

private void SystemDevicesChangedHandler(object sender, SystemAudioDevicesEventArgs e)
        {
            if (e.IsInputDevice) return;

            IMMDeviceEnumerator deviceEnumerator = (IMMDeviceEnumerator)new MMDeviceEnumerator();
            deviceEnumerator.EnumAudioEndpoints(EDataFlow.eRender, (uint)DeviceState.Active, out IMMDeviceCollection deviceCollection);
            deviceCollection.GetCount(out uint count);
            Marshal.ReleaseComObject(deviceEnumerator);
            if (deviceCollection != null) Marshal.ReleaseComObject(deviceCollection);

            if (e._notification == SystemAudioDevicesNotification.Activated)
            {
                if (count == 1)
                {
                    if (_playing && !_paused)
                    {
                        // cannot resume playback
                        //if (pm_HasPeakMeter)
                        //{
                        //    PeakMeter_Open(_audioDevice, true);
                        //}
                        // maybe this
                        Control control = _display;
                        if (control == null)
                        {
                            FormCollection forms = Application.OpenForms;
                            if (forms != null && forms.Count > 0) control = forms[0];
                        }
                        if (control != null)
                        {
                            control.BeginInvoke(new MethodInvoker(delegate { AV_UpdateTopology(); }));
                        }
                    }
                    _mediaAudioDeviceChanged?.Invoke(this, EventArgs.Empty);
                }
            }
            else if (_audioDevice == null)
            {
                if (pm_HasPeakMeter && e._notification == SystemAudioDevicesNotification.DefaultChanged)
                {
                    if (count != 0)
                    {
                        PeakMeter_Open(_audioDevice, true);
                    }
                    else pm_PeakMeterChannelCount = 0;
                    _mediaAudioDeviceChanged?.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                if (e._deviceId == _audioDevice.Id && (e._notification == SystemAudioDevicesNotification.Removed || e._notification == SystemAudioDevicesNotification.Disabled))
                {
                    if (count != 0)
                    {
                        _audioDevice = null;
                        if (pm_HasPeakMeter) PeakMeter_Open(_audioDevice, true);
                    }
                    else pm_PeakMeterChannelCount = 0;
                    _mediaAudioDeviceChanged?.Invoke(this, EventArgs.Empty);
                }
            }
        }

19 View Source File : UIMessages.cs
License : GNU General Public License v3.0
Project Creator : BRH-Media

public static void ThreadSafeMessage(string msg, string replacedle = @"Message", MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxIcon icon = MessageBoxIcon.Information)
        {
            //all currently open Windows Forms (will not work on startup due to this)
            var openForms = Application.OpenForms;

            //make sure that there is a form to invoke first
            if (openForms.Count > 0)
            {
                //the first form will be 'Home'
                var form = openForms[0];

                //thread-safe logic
                if (form.InvokeRequired)
                {
                    form.BeginInvoke((MethodInvoker)delegate
                    {
                        MessageBox.Show(msg, replacedle, buttons, icon);
                    });
                }
                else
                    MessageBox.Show(msg, replacedle, buttons, icon);
            }
        }

19 View Source File : MF_PlayerCallBack.cs
License : GNU General Public License v3.0
Project Creator : BRH-Media

public HResult Invoke(IMFAsyncResult result)
        {
            IMFMediaEvent   mediaEvent      = null;
            MediaEventType  mediaEventType  = MediaEventType.MEUnknown;
            bool getNext = true;

            try
            {
                _base.mf_MediaSession.EndGetEvent(result, out mediaEvent);
                mediaEvent.GetType(out mediaEventType);
                mediaEvent.GetStatus(out HResult errorCode);

                if (_base._playing)
                {
                    if (mediaEventType == MediaEventType.MEError
                        || (_base._webcamMode && mediaEventType == MediaEventType.MEVideoCaptureDeviceRemoved)
                        || (_base._micMode && mediaEventType == MediaEventType.MECaptureAudioSessionDeviceRemoved))
                        //if (errorCode < 0)
                    {
                        _base._lastError    = errorCode;
                        errorCode           = Player.NO_ERROR;
                        getNext             = false;
                    }

                    if (errorCode >= 0)
                    {
                        if (!getNext || mediaEventType == MediaEventType.MESessionEnded)
                        {
                            if (getNext)
                            {
                                _base._lastError = Player.NO_ERROR;
                                if (!_base._repeat && !_base._chapterMode) getNext = false;
                            }

                            Control control = _base._display;
                            if (control == null)
                            {
                                FormCollection forms = Application.OpenForms;
                                if (forms != null && forms.Count > 0) control = forms[0];
                            }
                            if (control != null) control.BeginInvoke(CallEndOfMedia);
                            else _base.AV_EndOfMedia();
                        }
                    }
                    else _base._lastError = errorCode;
                }
                else _base._lastError = errorCode;
            }
            finally
            {
                if (getNext && mediaEventType != MediaEventType.MESessionClosed) _base.mf_MediaSession.BeginGetEvent(this, null);
                if (mediaEvent != null) Marshal.ReleaseComObject(mediaEvent);

                if (_base.mf_AwaitCallBack)
                {
                    _base.mf_AwaitCallBack = false;
                    _base.WaitForEvent.Set();
                }
                _base.mf_AwaitDoEvents = false;
            }
            return 0;
        }

See More Examples