Click here to Skip to main content
15,921,716 members
Home / Discussions / C#
   

C#

 
AnswerRe: dll loading? Pin
Christian Graus11-Oct-09 10:28
protectorChristian Graus11-Oct-09 10:28 
AnswerRe: dll loading? Pin
freakyit11-Oct-09 22:22
freakyit11-Oct-09 22:22 
QuestionData Structure Pin
phobberman11-Oct-09 8:05
phobberman11-Oct-09 8:05 
AnswerRe: Data Structure Pin
riced12-Oct-09 6:21
riced12-Oct-09 6:21 
GeneralRe: Data Structure Pin
phobberman13-Oct-09 0:01
phobberman13-Oct-09 0:01 
QuestionTextbox Enter Event Pin
jonneale11-Oct-09 7:26
jonneale11-Oct-09 7:26 
AnswerRe: Textbox Enter Event Pin
N a v a n e e t h11-Oct-09 7:43
N a v a n e e t h11-Oct-09 7:43 
QuestionCreate dll and use it on runtime Pin
bonzaiholding11-Oct-09 7:11
bonzaiholding11-Oct-09 7:11 
AnswerRe: Create dll and use it on runtime Pin
Luc Pattyn11-Oct-09 8:05
sitebuilderLuc Pattyn11-Oct-09 8:05 
QuestionIS there a different in WebService programming in 32bit and 64bit ? Pin
E_Gold11-Oct-09 6:54
E_Gold11-Oct-09 6:54 
AnswerRe: IS there a different in WebService programming in 32bit and 64bit ? Pin
dan!sh 11-Oct-09 7:34
professional dan!sh 11-Oct-09 7:34 
QuestionWindow Address Pin
curtuy11-Oct-09 5:48
curtuy11-Oct-09 5:48 
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 

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.