Click here to Skip to main content
15,896,154 members
Home / Discussions / C#
   

C#

 
AnswerRe: Window Address Pin
Luc Pattyn11-Oct-09 5:55
sitebuilderLuc Pattyn11-Oct-09 5:55 
GeneralRe: Window Address Pin
curtuy11-Oct-09 6:03
curtuy11-Oct-09 6:03 
QuestionRe: Window Address Pin
harold aptroot11-Oct-09 5:55
harold aptroot11-Oct-09 5:55 
JokeRe: Window Address Pin
Eddy Vluggen11-Oct-09 6:03
professionalEddy Vluggen11-Oct-09 6:03 
GeneralRe: Window Address Pin
curtuy11-Oct-09 6:05
curtuy11-Oct-09 6:05 
AnswerRe: Window Address Pin
dan!sh 11-Oct-09 7:31
professional dan!sh 11-Oct-09 7:31 
GeneralRe: Window Address Pin
curtuy12-Oct-09 1:14
curtuy12-Oct-09 1:14 
QuestionThreadpool help [modified] Pin
OptiPlex11-Oct-09 5:45
OptiPlex11-Oct-09 5:45 
Hello,
Im trying to make a multithreaded proxy tester/scanner.
http://i36.tinypic.com/2m5jllf.jpg[^]

here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Threading;

namespace WebProxyTest
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            for(int i = 0; i < lstProxies.Items.Count; i++){
                string proxy = lstProxies.Items[i].ToString();

                string[] proxyinfo = proxy.Split(':');
                string proxyhost = proxyinfo[0];
                int proxyport = Convert.ToInt32(proxyinfo[1]);
                WebProxyTest test = new WebProxyTest(proxyhost, proxyport, "http://google.com/");

                ThreadPool.SetMaxThreads(10, 2);
                ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessProxies), test);
            }
        }

        private void ProcessProxies(object state){
            WebProxyTest test = state as WebProxyTest;
            test.TestProxy();
            //lstProxies.Items.Add("Result : " + test.ProxyResult);
            lstResults.Items.Add("Result: " + test.ProxyResult);
        }

    }
}

using System;
using System.Collections.Generic;
using System.Text;

using System.IO;
using System.Web;
using System.Net;

namespace WebProxyTest
{
    class WebProxyTest
    {
        private string proxyhost;
        private int proxyport;
        private string url;

        private string proxy_result = "none";
        public string ProxyResult {
            get {
                return proxy_result;
            }
            set {
                proxy_result = value;
            }
        }

        public WebProxyTest(string proxyhost, int proxyport, string url)
        {
            this.proxyhost = proxyhost;
            this.proxyport = proxyport;
            this.url = url;
        }

        public void TestProxy()
        {
            try
            {

                WebProxy proxy = new WebProxy(String.Format("http://{0}:{1}/", proxyhost, proxyport), true);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Proxy = proxy;
                request.Method = "GET";

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);

                string result = reader.ReadToEnd();

                proxy_result = "Done: Got " + result.Length;

                System.Windows.Forms.Clipboard.SetText(result);

                response.Close();
                reader.Close();
            }
            catch (System.Exception ex)
            {
                proxy_result = "Error: " + ex.Message;
            }
        }
    }
}


the problem is at this line:
test.TestProxy();

and/or
lstResults.Items.Add("Result: " + test.ProxyResult);


when I call a function/property of the WebProxyTest class I get an exception with something like:
"Error: The current thread is the mode Single Thread Apartment (STA) be brought before OLE calls can be made. Verify that the main function STAThreadAttribute is highlighted."


any ideas?
Thanks in advance




modified on Sunday, October 11, 2009 1:10 PM

AnswerRe: Threadpool help Pin
Luc Pattyn11-Oct-09 5:53
sitebuilderLuc Pattyn11-Oct-09 5:53 
GeneralRe: Threadpool help Pin
OptiPlex11-Oct-09 7:04
OptiPlex11-Oct-09 7:04 
GeneralRe: Threadpool help Pin
Luc Pattyn11-Oct-09 7:50
sitebuilderLuc Pattyn11-Oct-09 7:50 
QuestionCall a method using Windows forms Pin
Tamara Clifton11-Oct-09 5:43
Tamara Clifton11-Oct-09 5:43 
AnswerRe: Call a method using Windows forms Pin
dan!sh 11-Oct-09 5:57
professional dan!sh 11-Oct-09 5:57 
QuestionMonitor keys while the control is NOT in focus Pin
p3rson11-Oct-09 4:44
p3rson11-Oct-09 4:44 
AnswerRe: Monitor keys while the control is NOT in focus Pin
stancrm11-Oct-09 4:48
stancrm11-Oct-09 4:48 
AnswerRe: Monitor keys while the control is NOT in focus Pin
Anthony Mushrow11-Oct-09 7:06
professionalAnthony Mushrow11-Oct-09 7:06 
QuestionReturning datatable/dataset by from server in a Multithread Client server socket programming Pin
AhmedMasum11-Oct-09 2:55
AhmedMasum11-Oct-09 2:55 
AnswerRe: Returning datatable/dataset by from server in a Multithread Client server socket programming Pin
Eddy Vluggen11-Oct-09 3:51
professionalEddy Vluggen11-Oct-09 3:51 
GeneralRe: Returning datatable/dataset by from server in a Multithread Client server socket programming Pin
AhmedMasum12-Oct-09 4:25
AhmedMasum12-Oct-09 4:25 
GeneralRe: Returning datatable/dataset by from server in a Multithread Client server socket programming Pin
Eddy Vluggen12-Oct-09 5:25
professionalEddy Vluggen12-Oct-09 5:25 
QuestionTracing different threads Pin
manustone11-Oct-09 2:11
manustone11-Oct-09 2:11 
AnswerRe: Tracing different threads Pin
Keith Barrow11-Oct-09 2:30
professionalKeith Barrow11-Oct-09 2:30 
Questionopen exe file Pin
Member 432709611-Oct-09 1:28
Member 432709611-Oct-09 1:28 
AnswerRe: open exe file Pin
dataminers11-Oct-09 1:53
dataminers11-Oct-09 1:53 
AnswerRe: open exe file Pin
Md. Marufuzzaman11-Oct-09 2:12
professionalMd. Marufuzzaman11-Oct-09 2:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.