locked
relationship between forms RRS feed

  • Question

  • Form A process

    mail gönderme işleminde döngüden once

    before loop in mail sent

    Core.Sendcount=0;

    var frm = new PopupForm()

    frm.Show();

    //////loop

    mail.send()

    Core.Sendcount++

    ///////////

    Form B process

    Form Load code

     var sb=new StringBuilder();
                sb.Append("----------"+DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")+"----------");
                sb.Append(Environment.NewLine);          
                sb.Append(DateTime.Now.ToString("HH:mm:ss") + " Sending Process Count" + Core.Sendcount);
                sb.Append(Environment.NewLine);
                sb.Append("----------"+DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")+"----------");
                richTextBox1.Text = sb.ToString();

    So , my question is , if I want to send mail 5 person then Core.Sendcount=5 and I want to catch this value in B form

    But Form B Show to 0 number.

    • Moved by CoolDadTx Friday, November 16, 2018 3:35 PM Winforms related
    Friday, November 16, 2018 3:14 PM

Answers

  • Hi,

    >> I ask for that you give me better solution

    You can also try this to achieve it:

        private void OnTimeEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            Core.Sendcount++;
            if (Core.Sendcount == 3)
            {
                t.Enabled = false;
            }
            // code omitted
        }

    >> I want to use this scenario in progressbar

    Do you mean to show the progress of the loop execution in "ProgressBar"? If so, you can try this.

        private void Gonderal_Load(object sender, EventArgs e)
        {
            t = new System.Timers.Timer();
            // code omitted
            // …
            // code omitted
            richTextBox1.Text += sb.ToString();
    
            progressBar1.Maximum = 3;
            progressBar1.Minimum = 0;
        }
        private void OnTimeEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            Core.Sendcount++;
            // code omitted
            // …
            // code omitted
            richTextBox1.Text += sb.ToString();
    
            Thread thread = new Thread(new ThreadStart((delegate
            {
                progressBar1.Value = Core.Sendcount;
            })));
            thread.Start();
        }

    Note: In general, one thread is discussing and talking about one question, I'm afraid your new problem is a new question, please create a new thread to post a new question, and if my reply above solved your problem, please close this thread by marking the helpful reply as answer as this will help others looking for the same or similar issues down the road.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Aly14 Tuesday, November 20, 2018 10:17 AM
    Tuesday, November 20, 2018 9:42 AM

All replies

  • Hi,

    >>  if I want to send mail 5 person then Core.Sendcount=5 and I want to catch this value in B form. But Form B Show to 0 number.

    I'm afraid you need to loop the code before showing the FormB:

        Core.Sendcount = 0;
        //loop
        for (int i = 0; i < 5; i++)
        {
            // mail.send();
            Core.Sendcount++;
        }
        //Load FormB
        var frm = new PopupForm();
        frm.Show();

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 19, 2018 2:13 AM
  • your's scenario Show to complete results , I want to Show line by line

                sb.Append("----------"+DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")+"----------");
                sb.Append(Environment.NewLine);          
                sb.Append(DateTime.Now.ToString("HH:mm:ss") + " Sending Process Count" + "1");
                sb.Append(Environment.NewLine);
                sb.Append("----------"+DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")+"----------");
                richTextBox1.Text = sb.ToString();

    richTextBox1.Clear();

     sb.Append("----------"+DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")+"----------");
                sb.Append(Environment.NewLine);          
                sb.Append(DateTime.Now.ToString("HH:mm:ss") + " Sending Process Count" + "2");
                sb.Append(Environment.NewLine);
                sb.Append("----------"+DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")+"----------");
                richTextBox1.Text = sb.ToString();

    richTextBox1.Clear();

     sb.Append("----------"+DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")+"----------");
                sb.Append(Environment.NewLine);          
                sb.Append(DateTime.Now.ToString("HH:mm:ss") + " Sending Process Count" + "3");
                sb.Append(Environment.NewLine);
                sb.Append("----------"+DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")+"----------");
                richTextBox1.Text = sb.ToString();


    • Edited by Aly14 Monday, November 19, 2018 7:40 AM a
    Monday, November 19, 2018 7:38 AM
  • Hi,

    >> I want to Show line by line

    Do you mean to output the results after each send in turn? If so, try this.

    FormA:

        public Form1()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            Core.Sendcount = 0;
            //loop
            var frm = new PopupForm();
            frm.Show();
            Thread th = new Thread(new ThreadStart(delegate
            {
                for (int i = 0; i < 5; i++)
                {
                    Core.Sendcount++;
                    // simulate mail.send();
                    Thread.Sleep(1000);
                    PopupForm.form.ShowTime();
                }
            }));
            th.Start();
        }

    FormB:

        public static PopupForm form;
        public PopupForm()
        {
            InitializeComponent();
            form = this;
        }
    
        public void ShowTime()
        {
            richTextBox1.Clear();
            var sb = new StringBuilder();
            sb.Append("----------" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "----------");
            sb.Append(Environment.NewLine);
            sb.Append(DateTime.Now.ToString("HH:mm:ss") + " Sending Process Count" + Core.Sendcount);
            sb.Append(Environment.NewLine);
            sb.Append("----------" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "----------");
            sb.Append(Environment.NewLine);
            richTextBox1.Text += sb.ToString();
        }

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 19, 2018 8:45 AM
  • I applied your's demo its working , But its not working my structure maybe my loop process more than 1000 milisecond,

    I want to apply in Form B using timer like below,everything is working fine, But except Sending Process Count , its jumping 0 to 3 not 1-2-3

      System.Timers.Timer t;

            public Gonderal()
            {
                InitializeComponent();
            }

            private void Gonderal_Load(object sender, EventArgs e)
            {
                t = new System.Timers.Timer();
                t.Interval = 1000;
                t.Start();
                t.AutoReset = false;
                t.Elapsed += OnTimeEvent;

                richTextBox1.Clear();
       var sb = new StringBuilder();
       sb.Append("----------" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "----------");
       sb.Append(Environment.NewLine);
       sb.Append(DateTime.Now.ToString("HH:mm:ss") + " Sending Process Count" + 0);
       sb.Append(Environment.NewLine);
       sb.Append("----------" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "----------");
       sb.Append(Environment.NewLine);
                richTextBox1.Text += sb.ToString();
            }

           private void OnTimeEvent(object sender, System.Timers.ElapsedEventArgs e)
            {
                Thread th = new Thread(new ThreadStart(delegate
                 {
                Invoke(new Action(() =>
                {
                    Application.DoEvents();
                    Thread.Sleep(1000);

                    richTextBox1.Clear();
        var sb = new StringBuilder();
        sb.Append("----------" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "----------");
        sb.Append(Environment.NewLine);
        sb.Append(DateTime.Now.ToString("HH:mm:ss") + " Sending Process Count" + Core.Sendcount);
        sb.Append(Environment.NewLine);
        sb.Append("----------" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "----------");
        sb.Append(Environment.NewLine);
                    richTextBox1.Text += sb.ToString();

                }));
                }));
                th.Start();
               
            }
        }

    Monday, November 19, 2018 4:15 PM
  • Hi,

    >> maybe my loop process more than 1000 millisecond

    Since the new thread is created, this issue is independent of the time of the loop.

    >> But except Sending Process Count , its jumping 0 to 3 not 1-2-3

    In order to solve this issue, try this.

        System.Timers.Timer t;
        public Gonderal()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
        }
    
        private void Gonderal_Load(object sender, EventArgs e)
        {
            t = new System.Timers.Timer();
            t.Interval = 1000;
            t.Start();
            // set AutoReset to true
            t.AutoReset = true;
            // modify this line
            t.Elapsed += new System.Timers.ElapsedEventHandler(OnTimeEvent);
    
            richTextBox1.Clear();
            var sb = new StringBuilder();
            sb.Append("----------" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "----------");
            sb.Append(Environment.NewLine);
            sb.Append(DateTime.Now.ToString("HH:mm:ss") + " Sending Process Count" + 0);
            sb.Append(Environment.NewLine);
            sb.Append("----------" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "----------");
            sb.Append(Environment.NewLine);
            richTextBox1.Text += sb.ToString();
        }
        private void OnTimeEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            // Increment Core.Sendcount
            Core.Sendcount++;
            richTextBox1.Clear();
            var sb = new StringBuilder();
            sb.Append("----------" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "----------");
            sb.Append(Environment.NewLine);
            sb.Append(DateTime.Now.ToString("HH:mm:ss") + " Sending Process Count" + Core.Sendcount);
            sb.Append(Environment.NewLine);
            sb.Append("----------" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "----------");
            sb.Append(Environment.NewLine);
            richTextBox1.Text += sb.ToString();
        }

    More details about System.Timer, please refer to the following document:

    Timer Class

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 20, 2018 2:09 AM
  • if I set to t.AutoReset = true; timer not stop , so value continue 1-2-3-4-5-6 ..
    Tuesday, November 20, 2018 8:11 AM
  • Hi,

    To solve it, modify the code in "OnTimeEvent" event:

        private void OnTimeEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            // Increment Core.Sendcount
            Core.Sendcount++;
           // judge the count
            if (Core.Sendcount == 3)
            {
                t.Stop();
            }
            richTextBox1.Clear();
            var sb = new StringBuilder();
            // code omited
        }

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 20, 2018 8:25 AM
  • ok , I already done this ,I ask for that you give me better solution ,

    I have last problem , I want to use this scenario in progressbar , how can i do ,

    I am sorry , I have to open new ticket But it was hard to explain for new users due to we follow this scenario.

    Thank you in advance.

    Tuesday, November 20, 2018 8:58 AM
  • Hi,

    >> I ask for that you give me better solution

    You can also try this to achieve it:

        private void OnTimeEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            Core.Sendcount++;
            if (Core.Sendcount == 3)
            {
                t.Enabled = false;
            }
            // code omitted
        }

    >> I want to use this scenario in progressbar

    Do you mean to show the progress of the loop execution in "ProgressBar"? If so, you can try this.

        private void Gonderal_Load(object sender, EventArgs e)
        {
            t = new System.Timers.Timer();
            // code omitted
            // …
            // code omitted
            richTextBox1.Text += sb.ToString();
    
            progressBar1.Maximum = 3;
            progressBar1.Minimum = 0;
        }
        private void OnTimeEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            Core.Sendcount++;
            // code omitted
            // …
            // code omitted
            richTextBox1.Text += sb.ToString();
    
            Thread thread = new Thread(new ThreadStart((delegate
            {
                progressBar1.Value = Core.Sendcount;
            })));
            thread.Start();
        }

    Note: In general, one thread is discussing and talking about one question, I'm afraid your new problem is a new question, please create a new thread to post a new question, and if my reply above solved your problem, please close this thread by marking the helpful reply as answer as this will help others looking for the same or similar issues down the road.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Aly14 Tuesday, November 20, 2018 10:17 AM
    Tuesday, November 20, 2018 9:42 AM