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

  • SEARCH
  • Home
  • 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 8204533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:55:44+00:00 2026-06-07T07:55:44+00:00

I have a problem that has been driving me nuts for days.. I’ve tried

  • 0

I have a problem that has been driving me nuts for days.. I’ve tried so many tutorials and code snippets from this and many other websites. I am building a P2P application and i have problems accessing the main thread.
Here is the simple flow of my application:
1. frmMain is shown – user clicks on login button
2. frmlogin is shown – user enters his name
3. after “logging in” – two threads are created (threadTCPlistener and threadUDPlistener)
4. frmDataGrid is shown

Server listen = new Server();
Thread listeningUDPThread = new Thread(new ThreadStart(listen.startUDPServer));
listeningUDPThread.IsBackground = true;
listeningUDPThread.Start();
Thread listeningTCPThread = new Thread(new ThreadStart(listen.startTCPServer));
listeningTCPThread.IsBackground = true;
listeningTCPThread.Start();
frmDataGrid dg = new frmDataGrid();
dg.Show();

5.Threads work in one separate class called “Server”. In there they wait for incoming connections, and when TCP thread accepts a connection it starts receinving a file. Upon receiving the file, I would like to change the GUI in the frmDataGrid to add a new row to grid view. I’ve done something like this:

public void downloadFile()
{
     //--receiving of the file--
     frmDataGrid fdg = new frmDataGrid();
     //filename is the name of received file, and 100's are just for testing (for now).    
     fdg.verifyUIRequest(fileName, 100, 100);
}

I am calling a method from frmDataGrid VerifyUIRequest that looks like this:

 public void verifyUIRequest(string filename, int done, int percent)
     {
     if (dgvDown.InvokeRequired)
         {
         dgvDown.Invoke((MethodInvoker)delegate { updateDownDgv(filename, done, percent);  });
         }
     else
     {
         updateDownDgv(filename, done, percent);
     }

After this, the main thread should call the “updateDownDgv” method but the problem is that nothing is happening with my data grid. Here is the code for updating:

public void updateDownDgv(string filename, int done, int percent)
{
foreach (DataGridViewRow r in dgvDown.Rows)
{
        if ((string)r.Cells[0].Value == filename)
                {
                    r.Cells[1].Value = done;
                    r.Cells[2].Value = percent;
                }
                dgvDown.Invalidate();
                return;
 }
 DataTable tab = (DataTable)dgvDown.DataSource;
 DataRow row =  tab.NewRow();
 row[0] = filename;
 row[1] = percent;
 row[2] = done;
 //MessageBox.Show(done.ToString());
 tab.Rows.Add(row);
 dgvDown.DataSource = null;
 dgvDown.DataSource = tab;
 }

I have tried doing this withh begin invoke, with some lambda expressions but nothing succeded. Can anyone please point me to an error or help in some other way? I would really appreciate it.
PS This is my first post, so if it is poorly formatted, i apologize in advance. 🙂

EDIT:
So the problem is obviously with instances, so I’ve done something like this:
from Server class where I create an instance of my frmDataGrid class, i now call it’s constructor that takes 3 arguments.
frmDataGrid fdg = new frmDataGrid(fileName, 100, 100);
in that constructor, in frmDataGrid, I call verifyUIRequest. But then another error occurs, and I can’t seem to figure it out. It stops at

if (dgvDown.InvokeRequired)
{...

error is as folows:
“Object reference not set to an instance of an object”, i.e. NullReferenceException. What could be the error?

  • 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-06-07T07:55:45+00:00Added an answer on June 7, 2026 at 7:55 am

    You are creating a brand new data grid in your downloadFile method. You should be updating the main grid and calling methods on that from your thread methods, not creating a new one that you drop on the floor when the downloadFile method exits.

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

Sidebar

Related Questions

I have a problem that has been driving me batty. I have code that
I have a problem that has been driving me nuts. I create a Form
This has been driving me nuts all day. I have a weird bug that
I have a javascript function that has been driving me nuts. This is the
I have a problem which has been driving me mad for days - I've
I a problem that has been driving me nuts for awhile now. Here is
I have a problem that has been bothering me now for a few days.
I have the problem that my view controller class has too many delegates and
This has been driving me nuts all day. I've seen this problem crop up
This has been driving me nuts for a week now. I have a class

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.