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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Multithreading problem

Multithreading problem

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 Posts 3 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.
  • T Offline
    T Offline
    thepersonof
    wrote on last edited by
    #1

    Hi I know multithrading is explained in several tutorials, but I can't figure out how to terminate another thread gracefully. This is my current code. In thread1 when I dispose s I get an error... I realised this would happen with sychronisation etc. What can I do? public class Loader { PNG.SplashScreen s; Form1 f; Thread first; Thread second; public Loader() { first = new Thread(new ThreadStart(thread1)); second = new Thread(new ThreadStart(thread2)); first.Start(); second.Start(); } void thread1() { f = new Form1(); s.Dispose(); f.ShowDialog(); } void thread2() { s = new PNG.SplashScreen(); s.ShowDialog(); } } cheers

    J R 2 Replies Last reply
    0
    • T thepersonof

      Hi I know multithrading is explained in several tutorials, but I can't figure out how to terminate another thread gracefully. This is my current code. In thread1 when I dispose s I get an error... I realised this would happen with sychronisation etc. What can I do? public class Loader { PNG.SplashScreen s; Form1 f; Thread first; Thread second; public Loader() { first = new Thread(new ThreadStart(thread1)); second = new Thread(new ThreadStart(thread2)); first.Start(); second.Start(); } void thread1() { f = new Form1(); s.Dispose(); f.ShowDialog(); } void thread2() { s = new PNG.SplashScreen(); s.ShowDialog(); } } cheers

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      You can't really terminate another thread gracefully. You either kill it ungracefully via someThread.Abort (which injects the ThreadAbortException into the thread being aborted), or you can cancel gracefully by having someThread check for some boolean cancel state over time and exiting when it hits that state.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Goof around music jam with my brothers (with video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      1 Reply Last reply
      0
      • T thepersonof

        Hi I know multithrading is explained in several tutorials, but I can't figure out how to terminate another thread gracefully. This is my current code. In thread1 when I dispose s I get an error... I realised this would happen with sychronisation etc. What can I do? public class Loader { PNG.SplashScreen s; Form1 f; Thread first; Thread second; public Loader() { first = new Thread(new ThreadStart(thread1)); second = new Thread(new ThreadStart(thread2)); first.Start(); second.Start(); } void thread1() { f = new Form1(); s.Dispose(); f.ShowDialog(); } void thread2() { s = new PNG.SplashScreen(); s.ShowDialog(); } } cheers

        R Offline
        R Offline
        Robert Rohde
        wrote on last edited by
        #3

        You error most probably comes from the fact that it is only safe to alter GUI elements from within the thread they where created in. Have a look at the Invoke[^] method.

        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