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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:41:05+00:00 2026-06-12T07:41:05+00:00

I am new to developing with Windows forms applications and I have an issue

  • 0

I am new to developing with Windows forms applications and I have an issue I could do with some help / guidance on the best practice approach I should be taking.

Background:

I have an forms based application that needs to refresh every minute with data from a WCF service and then update the UI with the latest results in a List View control. I have this all working in principal but the application crashes intermittently and I need to resolve this. I have stripped out the main parts of the code below. The actual nuts and bolts are probably not required.

Code:

public partial class Form1 : Form
{
readonly MatchServiceReference.MatchServiceClient _client = new MatchServiceReference.MatchServiceClient();

public Form1()
    {
        _client.GetMMDataCompleted += new EventHandler<GetMMDataCompletedEventArgs>(_client_GetMMDataCompleted);
    }    

//Arm Timer
private void ArmTimer(object sender, EventArgs e)
    {
        aTimer = new Timer();

        aTimer.Elapsed += OnTimedEvent;

        aTimer.Interval = 60000;
        aTimer.Enabled = true;
    }

//Timer elapsed event
 private void OnTimedEvent(object source, ElapsedEventArgs e)
    {
        try
        {
            LoadMatches();

            if (LastUpdated.InvokeRequired)
            {
                LastUpdated.Invoke(new MethodInvoker(delegate { LastUpdated.Text = e.SignalTime.ToString(); }));
            }
        }
        catch (Exception exception)
        {

        }

    }

//Load matches
private void LoadMatches()
    {
        try
        {
            aTimer.Enabled = false;
            _client.GetMMDataAsync();
        }
        catch (Exception e)
        {
            //EventLog.WriteEntry("Application", e.InnerException.ToString(), EventLogEntryType.Error);
            aTimer.Enabled = true;
        }
    }

void _client_GetMMDataCompleted(object sender, GetMMDataCompletedEventArgs e)
    {
        if (e.Result != null)
        {

            var matches = e.Result;

            Debug.WriteLine("Matches received from service");

            if (!IsHandleCreated && !IsDisposed) return;

            // Invoke an anonymous method on the thread of the form.
            Invoke((MethodInvoker) delegate
                                       {
                                           try
                                           {
                                               LoadTheMonitorMatches(matches);
                                           }
                                           catch (Exception exception)
                                           {
                                               Debug.WriteLine("INNER EXCEPTION" + exception.InnerException);
                                               Debug.WriteLine("EXCEPTION MESSAGE" + exception.Message);
                                           }
                                       });
        }
        aTimer.Enabled = true;
    }
}

}

Exception:

The exception I am getting is as follows –

Exception Info: System.Reflection.TargetInvocationException
Stack:
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at MM.MatchServiceReference.GetMMDataCompletedEventArgs.get_Result()
at MM.Form1._client_GetMMDataCompleted(System.Object, MM.MatchServiceReference.GetMMDataCompletedEventArgs)
at MM.MatchServiceReference.MatchServiceClient.OnGetMMDataCompleted(System.Object)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
at System.Threading.ExecutionContext.runTryCode(System.Object)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Any help / advice with this would be greatly appreciated.

Cheers

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

    The line

      if (e.Result != null)
    

    is actually calling the getter for result. Since the event args derive from AsyncCompletedEventArgs this can raise an error if the operation was cancelled or errored. Check the cancelled and error properties first before testing the result and you should be able to trap the problem.

    From the docs:
    If the component's asynchronous worker code assigns an exception to the Error property or sets the Cancelled property to true, the property will raise an exception if a client tries to read its value.

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

Sidebar

Related Questions

I'm developing a windows forms application. And i have the following issue: in a
I am developing a windows based application in .net. I have two forms. Form2
I am developing a new web application for the Windows Azure cloud, but have
I'm configuring a new Developing Server that came with Windows 7 64bits. It must
I just started developing my brand new windows 8 application last week using mvvm
I am new to developing code in iPhone, and I want to search some
I am fairly new at developing for Android and was hoping to get some
I'm new to developing in SharePoint and would like some tips please. I want
I'm new to developing with xCode and Objective C, and I have a simple
I am very new to developing applications with LibGDX and 3D apps in general

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.