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 6582929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:20:36+00:00 2026-05-25T16:20:36+00:00

Usually I handle my bugs by myself but this time I need help of

  • 0

Usually I handle my bugs by myself but this time I need help of experts!
This never happened to me, and the less data one has (usually) the less you can say what happened.

I am trying to write a simple query analyser. I randomly receive these kind of crashes:

1) I am starting with the following function:

Dim thd As New Thread(AddressOf StartSub)
thd.Start()

then the Startsub follows:

 Public Sub StartSub()
    CheckForIllegalCrossThreadCalls = False
    txtExecution.Text = "Executing query..."
    Dim query As String = QueryBuilder()
    UpdateView(query)
End Sub

and then the updateview updates the datagrid I have:

    Dim da As New SqlCeDataAdapter(query, connStr)
    Dim dt As New DataTable()
    Try
        da.Fill(dt)
        txtExecution.Text = "Query executed successfully."
        dgTickets.DataSource = dt
    Catch ex As Exception
        txtExecution.Text = "Query failed."
        tbGrid.BeginInvoke(Sub() tbGrid.SelectedTab = tbGrid.TabPages(1))
    End Try

2) The code crashes in UpdateQuery on the following line (debugger does not say that it crashes here, I guessed it by selecting all lines and going through it 1 by 1):

dgTickets.DataSource = dt

3) What the debugger says:
NullReferenceException was unhandled(…)
use the new keyword to create an object instance

stack trace:

at System.Windows.Forms.DataGridViewCell.GetEditedFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle& dataGridViewCellStyle, DataGridViewDataErrorContexts context)
   at System.Windows.Forms.DataGridViewCell.PaintWork(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
   at System.Windows.Forms.DataGridViewRow.PaintCells(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow, DataGridViewPaintParts paintParts)
   at System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow)
   at System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle boundingRect, Rectangle clipRect, Boolean singleHorizontalBorderAdded)
   at System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds, Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
   at System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.DataGridView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(ApplicationContext context)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at SQLquery.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 

This is pretty vague actually. The file specified above does not exist. The place where it crashes is wrapped with Try-End Try. Moreover, yes, I have the painting event set up but it should not concern it (or maybe it does?).

I would really appreciate very very much any hints as far as this one. I have to add that I use visual basic express edition. The error occurs ocasionally – sometimes when I’m lucky nothing happens, and when I’m not then I get this crash.

Pete.

  • 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-25T16:20:36+00:00Added an answer on May 25, 2026 at 4:20 pm

    You should never touch/update any GUI controls inside background threads. So lines like:

    txtExecution.Text = "Executing query..."
    

    and

    dgTickets.DataSource = dt
    

    inside a background thread are doomed to fail. This should always be done on the main GUI thread using Control.BeginInvoke.

    The only GUI update that you seem to be doing correctly is this tbGrid in the catch:

    tbGrid.BeginInvoke(Sub() tbGrid.SelectedTab = tbGrid.TabPages(1))
    

    You should read about UI WinForms thread invokes.

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

Sidebar

Related Questions

I worked with libevent2 for some time, but usually I used it to handle
Usually when I need to fork in C, I do something like this: pid_t
Ok, I usually do this in reverse, post a specific data set, then expect
I usually use ax.set_rasterized(True) to rasterize the figure so that it could handle transparency
Usually when I build a site, I put all the CSS into one file,
I usually write the following to handle a right mouse click. if (e.Button ==
Can REST web service (which usually produces e.g. simple JSONs ) both handle and
I'm usually testing this alongside a string == null , so I'm not really
What's your deep comprehension of pointer,reference and Handle in C,C++ and Java? We usually
I need to handle a lot of incoming XMLs which may be rather complex.

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.