コード例 #1
0
        public static int WS_CAPTION  = WS_BORDER | WS_DLGFRAME; //window with a title bar
        #endregion

        #region // hàm gọi từ usercontrol
        public void Closeemulator(String pid, string name)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                Process[] process = Process.GetProcesses();

                foreach (Process prs in process)
                {
                    if (prs.Id == int.Parse(pid))
                    {
                        prs.Kill();
                        break;
                    }
                }
            }
            catch { }
            try
            {
                foreach (Control control in flowLayoutPanelContent.Controls)
                {
                    if (control.GetType() == typeof(UC_Emulator))
                    {
                        UC_Emulator movie = (UC_Emulator)control;
                        flowLayoutPanelContent.Controls.Remove(control);
                        control.Dispose();
                    }
                }
            }
            catch { }
            this.Cursor = Cursors.Default;
        }
コード例 #2
0
        private void btnchaymayao_Click(object sender, EventArgs e)
        {
            DataTable table = new DataTable();

            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("Phone", typeof(string));
            foreach (DataGridViewRow row in Listemulator.Rows)
            {
                int  i   = row.Index;
                bool chk = false;
                try
                {
                    chk = bool.Parse(Listemulator.Rows[i].Cells[0].Value.ToString());
                }
                catch { }
                if (chk == true)
                {
                    int    id   = int.Parse(Listemulator.Rows[i].Cells["ID"].Value.ToString());
                    string mail = Listemulator.Rows[i].Cells["Phone"].Value.ToString();
                    Listemulator.Rows[i].DefaultCellStyle.BackColor = Color.Beige;
                    table.Rows.Add(id, mail);
                }
            }
            if (table.Rows.Count > 0)
            {
                #region //chay tạo emulator
                foreach (DataRow row in table.Rows)
                {
                    int    idmail = int.Parse(row["ID"].ToString());
                    string m_mail = row["Phone"].ToString();

                    try
                    {
                        Process p = new Process();
                        p.StartInfo.FileName  = txtpathldplayer.Text;//.Replace(".exe", idmail + ".exe");
                        p.StartInfo.Arguments = "index =" + idmail.ToString();
                        p.Start();
                        p.WaitForInputIdle();
                        UC_Emulator a = new UC_Emulator(p.Id.ToString(), m_mail, idmail.ToString());
                        flowLayoutPanelContent.Controls.Add(a);
                        Thread.Sleep(4000);
                        SetParent(p.MainWindowHandle, a.Handle);
                        int style = GetWindowLong(p.MainWindowHandle, GWL_STYLE);
                        SetWindowLong(p.MainWindowHandle, GWL_STYLE, (style & ~WS_DLGFRAME));
                        MoveWindow(p.MainWindowHandle, -33, -33, 300, 450, true);
                        Thread.Sleep(1000);
                    }
                    catch { }
                }
                #endregion
            }
            else
            {
                MessageBox.Show("Hãy chọn kênh cần open emulator", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
コード例 #3
0
        private void CreateControl(int maxConcurrency)
        {
            int soluong = 0;

            foreach (Control control in flowLayoutPanelContent.Controls)
            {
                if (control.GetType() == typeof(UC_Emulator))
                {
                    soluong = soluong + 1;
                }
            }
            if (soluong < maxConcurrency)
            {
                for (int i = 0; i < maxConcurrency - soluong; i++)
                {
                    UC_Emulator a = new UC_Emulator("0", "Chưa có Phone", "0");
                    flowLayoutPanelContent.Controls.Add(a);
                }
            }
        }
コード例 #4
0
        private void btnchaytheoluong_Click(object sender, EventArgs e)
        {
            int maxConcurrency = int.Parse(txtsoluong.Value.ToString());

            #region // tạo sẵn số UC trong panel
            CreateControl(maxConcurrency);
            #endregion

            DataTable dt = (DataTable)Listemulator.DataSource;
            using (SemaphoreSlim concurrencySemaphore = new SemaphoreSlim(maxConcurrency))
            {
                List <Task> tasks = new List <Task>();
                foreach (DataRow r in dt.Rows)
                {
                    concurrencySemaphore.Wait();
                    var t = Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            int idmail    = int.Parse(r["ID"].ToString());
                            string m_mail = r["Phone"].ToString();

                            Process p             = new Process();
                            p.StartInfo.FileName  = txtpathldplayer.Text;//.Replace(".exe", idmail + ".exe");
                            p.StartInfo.Arguments = "index =" + idmail.ToString();
                            p.Start();
                            p.WaitForInputIdle();
                            foreach (Control control in flowLayoutPanelContent.Controls)
                            {
                                if (control.GetType() == typeof(UC_Emulator))
                                {
                                    UC_Emulator movie = (UC_Emulator)control;
                                    if (movie.m_idprosess == "0")
                                    {
                                        movie.m_idprosess = p.Id.ToString();
                                        movie.m_name      = m_mail;
                                        movie.m_idphone   = idmail.ToString();
                                        movie.loadname();
                                        Thread.Sleep(5000);
                                        SetParent(p.MainWindowHandle, movie.Handle);
                                        int style = GetWindowLong(p.MainWindowHandle, GWL_STYLE);
                                        SetWindowLong(p.MainWindowHandle, GWL_STYLE, (style & ~WS_DLGFRAME));
                                        MoveWindow(p.MainWindowHandle, -33, -33, 300, 450, true);
                                        Thread.Sleep(15000);
                                        CloseemulatorV2(p.Id.ToString(), m_mail);
                                        movie.m_idprosess = "0";
                                        movie.m_name      = "Chưa có Phone";
                                        movie.m_idphone   = "0";
                                    }
                                }
                            }
                        }
                        finally
                        {
                            concurrencySemaphore.Release();
                        }
                    });

                    tasks.Add(t);
                }
                Task.WaitAll(tasks.ToArray());
            }
        }