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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:10:11+00:00 2026-05-26T17:10:11+00:00

I have a class: class ShowComboBoxUpdater { private ComboBox _showComboBox; private String _searchString; private

  • 0

I have a class:

class ShowComboBoxUpdater
{
    private ComboBox _showComboBox;
    private String _searchString;
    private RequestState _endState;

    public event EventHandler ResultUpdated;

    public string[] getShowList()
    {
        if (_endState.serverQueryResult != null)
            return _endState.serverQueryResult;
        return new string[] { "" };
    }

    public ShowComboBoxUpdater(ComboBox combo, Image refreshImage)
    {
        _showComboBox = combo;
        _refreshImage = refreshImage;
        _endState = new RequestState();
    }

    public void RequestUpdatingComboSource()
    {
        _searchString = _showComboBox.Text;
        Thread t = new Thread(new ThreadStart(MakeServerConnectionThread));
        t.IsBackground = true;
        t.Start();
    }

    private void MakeServerConnectionThread()
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://services.tvrage.com/myfeeds/search.php?show=" + _searchString);
        _endState.request = request;
        IAsyncResult result = request.BeginGetResponse(new AsyncCallback(RequestingThread), _endState);
        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(ScanTimeoutCallback), _endState, (30 * 1000), true);
    }

    private void RequestingThread(IAsyncResult result)
    {
        RequestState state = (RequestState)result.AsyncState;
        WebRequest request = (WebRequest)state.request;

        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
        Stream bodyStream = response.GetResponseStream();
        StreamReader r = new StreamReader(bodyStream);
        string xmlResponse = r.ReadToEnd().Trim();

        using (StringReader XMLStream = new StringReader(xmlResponse))
        {
            XPathNavigator feed = new XPathDocument(XMLStream).CreateNavigator();
            XPathNodeIterator nodesNavigator = (XPathNodeIterator)feed.Evaluate("descendant::show/name/text()");
            int titlesCount = nodesNavigator.Count;
            string[] titles = new string[titlesCount];
            foreach (XPathNavigator n in nodesNavigator)
            {
                titles[--titlesCount] = n.Value;
            }
            state.serverQueryResult = titles;
            if (this.ResultUpdated != null) this.ResultUpdated(this, new EventArgs());
        }
    }

    private static void ScanTimeoutCallback(object state, bool timedOut)
    {
        if (timedOut)
        {
            RequestState reqState = (RequestState)state;
            if (reqState != null)
                reqState.request.Abort();
        }
    }
}

In my main thread I create ShowComboBoxUpdater and connect event ResultUpdate to other event. Then I am calling RequestUpdatingComboSource() method. I have my event activated but, how can I get the resulting serverQueryResult ? I know it’s there but everything that I try results in exception that what I want to get is "owned by other thread".

  • 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-26T17:10:11+00:00Added an answer on May 26, 2026 at 5:10 pm

    How to pass value ?

    public class MyArgs : EventArgs
        {
            //Declare any specific type here
            public string ResultToPass { get; private set; }
            public MyArgs()
            {
            }
        }
    
    if (this.ResultUpdated != null) this.ResultUpdated(this, new MyArgs(){ResultToPass="Your actual result"} );
    

    How to update result ?

    Capture SynchronizationContext of the UI ( main thread) in order to instruct whenever you want the value to be updated back in the UI. Send/Post method on the captured SynchronizationContext reference in order to push the message into UI thread.

    public partial class MainWindow : Window 
        { 
            SynchronizationContext UISyncContext; 
            public MainWindow() 
            { 
                InitializeComponent(); 
            } 
            public StartProcessing() 
            { 
                //Let say this method is been called from UI thread. i.e on a button click 
                //capture the current synchronization context 
    
                UISyncContext=TaskScheduler.FromCurrentSynchronizationContext; 
             }     
           public UpdateResultInUI() 
            { 
                //Let's say this is is the method which user triggers at 
                //some point in time ( with the assumption that we have Myresult in hand) 
    
                if(UISyncContext!=null) 
                    UISyncContext.Send(new SendOrPostCallback(delegate{ PutItInUI }),null); 
    
                //Use Send method - to send your request synchronously 
                //Use Post method- to send your request asynchronously 
            } 
            void PutItInUI() 
            { 
                //this method help you to put your result in UI/controls 
            } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class like public class ProgressBars { public ProgressBars() { } private Int32
I have: class first{ private: int *array; public: first(int x){ array = new int[x][10];
I have class like this: public class object { [Key] int number; String mystring;
I have class Foo. Foo has a property of public string x. I would
I have class: static class GetRole { public static string OfUser(string username) { string
I have class public class Class2 { public string myName { get; set; }
I have class A: public class ClassA<T> Class B derives from A: public class
I have class A, which exposes an event. an object of class B subscribed
I have class A: public B { ...} vector<A*> v; I want to do
I have class Fred { public: void inspect() const {}; void modify(){}; }; int

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.