S
S
Stepan Davashenevquestion2020-05-15 17:47:56
C++ / C#
Stepan Davashenevquestion, 2020-05-15 17:47:56

How to update a form from another class on an event?

what I currently have

class form1.cs
start on click

private void StartGetQuery_Click(object sender, EventArgs e)
        {
            var QB = new QueryBig();
            QB.StartLoaded();
        }
// обновляем форму
        public void LogShow(string LogString)
        {
            StatusStringPars.Text = String.Format(LogString);
        }

another class QueryBig.cs
public void getNewMesQuery()
        {
            Dictionary<string, Object> MesageArr = new Dictionary<string, Object>(1);
            
            string response = getSendDataServer(MesageArr, "http://api.spmail/get/query");
            var MaFrame = new Form1();
            MaFrame.LogShow("response");
        }
        private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
        {
            this.getNewMesQuery();
        }
        // таймер
        private static System.Timers.Timer p_Timer;
        public void StartLoaded()
        {
            p_Timer = new System.Timers.Timer(1000);
            p_Timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            p_Timer.Enabled = true;
        }

StatusStringPars.Text = String.Format(LogString); - Nothing happens((((

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
baimkin, 2020-05-15
@baimkin

Try like this:

StatusStringPars.BeginInvoke(new Action(() => { StatusStringPars.Text = String.Format(LogString); }));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question