Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 213151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:15:07+00:00 2026-05-11T18:15:07+00:00

Till this moment I used this method to invoke: public string AddText { set

  • 0

Till this moment I used this method to invoke:

    public string AddText
    {
        set
        {
            if (listView1.InvokeRequired)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    Textbox.text += value + "\n";
                });
            }
            else
            {
                Textbox.text += value + "\n";
            }
        }
    }

And here is the problem:

    var form = Form.ActiveForm as Form1;
    if (form != null)
        form.AddText = "Test";

I’m writing an analyzer which analyze packets. I can’t put the form on focus all the time, because I have to do actions on the application. I’m writing this analyzer in order to get a packet so I can analyze it.

If I touch the application I want to analyze Form.ActiveForm returns null.

Is there a way I can invoke and set the textbox to add text even if the form is not on Top of everything?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:15:07+00:00Added an answer on May 11, 2026 at 6:15 pm

    I think the root of the problem is the tight coupling between your packet analyzer and the main form. A packet analyzer should not have to know anything about the active form, or even that there is any form at all. It makes things hard to maintain because it only works under a very specific circumstance that’s already untrue some of the time.

    You could turn the problem around, and raise an event from the class that is analyzing the packets. That gives you much better encapsulation because now the packet analyzer needs to know nothing about the rest of the application. You can either create your own event args or reuse one like System.Diagnostics.DataReceivedEventArgs for example. Then your form can sink the DataReceived event and call its own AddText to invoke back to the main thread, and it will work whether the form is visible or not.

    At least that will work but it is a blocking call so the packet analyzer thread will be stopped until the form fully handles the event and the marshalled call back to the main thread has returned. That would be okay if the paket rate isn’t very high but usually you wouldn’t want to stop a communication thread to wait for the main thread to update a textbox. Another approach would be to log the text using a StringBuilder inside the packet analyzer, and expose it (the accumulated text, not the StringBuilder) via a thread-safe public property. Or if you need to separate the invidual messages then you could add them to a List for example, and have the thread-safe property return an array of accumulated messages. Then your form could poll the analyzer for new logged data using a Timer at whatever rate is appropriate for your application, and only while the form is visible. It would not update quite as fast but the impact on the analyzer thread would be almost nil and it should run faster overall if it consolidates many messages inside the StringBuilder or List in between updates rather than concatenating on to the Text property with every single packet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 160k
  • Answers 160k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could override OnActionExecuting in that Controller class. protected override… May 12, 2026 at 11:43 am
  • Editorial Team
    Editorial Team added an answer See the difference between CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT May 12, 2026 at 11:43 am
  • Editorial Team
    Editorial Team added an answer To your first point. Why not only jar up the… May 12, 2026 at 11:43 am

Related Questions

I'm new to C#.Till this moment I used to make every global variable -
I'm using jquery and swfupload in order to upload files and photos. Worked fine
I'm a bit in IDE trouble, and I'm not alone I have noticed, still
I am trying to cross compile a version of my software for a 64bit

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.