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

The Archive Base Latest Questions

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

Using WPF and .NET 4.0. I’m downloading some data using WebClient and using DownloadStringCompletedEventHandler

  • 0

Using WPF and .NET 4.0.

I’m downloading some data using WebClient and using DownloadStringCompletedEventHandler to fire off my DownloadCompletedCallback function upon completion.

The issue I’m having is that when DownloadCompletedCallback is called I’m trying to set the contents of a label on the main form and am presented with the error.

An object reference is required for the non-static field, method, or property ‘Armory.MainWindow.lblDebug’.

I understand that it’s because the function DownloadCompletedCallback is declared as static but I don’t understand why that matters.

Here’s the code I’m using.

public static void DownloadHTML(string address)
{
    WebClient client = new WebClient();

    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadCompletedCallback);

    client.DownloadStringAsync(new Uri(address));
}

private static void DownloadCompletedCallback(Object sender, DownloadStringCompletedEventArgs e)
{
    if (!e.Cancelled && e.Error == null)
    {
        lblDebug.Content = (string)e.Result;
    }
}
  • 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-20T09:36:08+00:00Added an answer on May 20, 2026 at 9:36 am

    I understand that it’s because the
    function DownloadCompletedCallback is
    declared as static but I don’t
    understand why that matters.

    From the C# specification:

    A method declared with a static
    modifier is a static method. A static
    method does not operate on a specific
    instance and can only directly access
    static members. A method declared
    without a static modifier is an
    instance method.

    An instance method
    operates on a specific instance and
    can access both static and instance
    members. The instance on which an
    instance method was invoked can be
    explicitly accessed as this. It is an
    error to refer to this in a static
    method.

    It is because static methods aren’t part of the object, so they can’t interact with anything that is. They are tied to the class which has no concept of state, so when you call it, the static method has no idea which object the non-static object variables it should interact with.

    An example why it’s forbidden:

    Class Example{...}
    
    var ExampleOne = new Example();
    var ExampleTwo = new Example();
    
    Example.CallStaticMethod();
    

    So now the question becomes which non static variables should it interact with? Should it be ExampleOne or ExampleTwo, or should it just throw an null reference exception. In the first two cases there is no way for the system to know which it should interact with, because you never specified it (or it’d be an instance method). For the third, it’s not really static since you’d need to have an instance to call it. So accessing non-static methods properties etc. has to be forbidden, because there is too much ambiguity not to.

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

Sidebar

Related Questions

Using C# and WPF under .NET (rather than Windows Forms or console), what is
I just started using the WPF WebBrowser that is included in Net 3.5 SP1.
I am creating menus in WPF programatically using vb.net. Can someone show me how
I've been using Winforms since .NET 1.1 and I want to start learning WPF.
I'm building an application in C# using WPF. How can I bind to some
I have a situation where I am using wpf data binding and validation using
Using WPF, I have a TreeView control that I want to set its ItemTemplate
Anyone using WPF for real LOB applications? We have all seen the clever demos
i wonder if it is possible to cascade converters when using wpf databinding. e.g.
My company is just starting to look at using WPF for migrating all of

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.