Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Help ThreadPools/Threads

Help ThreadPools/Threads

Scheduled Pinned Locked Moved C#
businesshelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peterzorbas
    wrote on last edited by
    #1

    Im writing an application that will use the HTTPSocket class in SystemNet. I have checked the msdn documentation regarding thread safety which infact is safe to deploy the class in a thread however im unable to reach a code point of execution where data is supposed to be displayed. Better yet let me copy paste some simple code for everyone to see. The results are dubious. class MyThreadPool { private static int i; private string web_response; private string company; private long thread_id; public MyThreadPool() { } public MyThreadPool(string business_string, long id) { this.company = business_string; this.thread_id = id; ThreadPool.QueueUserWorkItem(new WaitCallback(HackCorps), new AutoResetEvent(true)); } public void HackCorps(Object state) { string[] business = null; business = this.company.Split('^'); Stream business_stream = WebRequest.Create(business[0]).GetResponse().GetResponseStream(); StreamReader business_reader = new StreamReader(business_stream); Console.WriteLine(++i); } } and the main int main(){ string line = null; long i = 0; StreamReader read_business = new StreamReader("f://directory.txt"); while ((line = read_business.ReadLine()) != null) { MyThreadPool pool = new MyThreadPool(line, ++i); }return 0;<----Code get here since all thread classes are created although they aren't processed will cause the probram to terminate. Is there some sort of lock to prevent this? } Thanks for your help...

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups