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. create a control inside a thread and update it

create a control inside a thread and update it

Scheduled Pinned Locked Moved C#
graphicsannouncement
2 Posts 2 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.
  • V Offline
    V Offline
    Vivek Vijayan
    wrote on last edited by
    #1

    create a control inside a thread and update it i need to create a thread and that thread creates a browser and update the image in browser each time it executes m geting nulref exception public void setWebBrowser() { Invoke(new EventHandler(workerAddBrowser)); } void workerAddBrowser(object sender, EventArgs e) { if (flag == 1) { browser.Refresh(); } browser = new WebBrowser(); Controls.Add(browser); browser.DocumentText =/* new Bitmap(File.Open("\\Program Files\\pic\\screen.jpg", FileMode.Open, FileAccess.Read));*/"<img src='file://\\Program Files\\syswifi\\pic\\screen.jpg' width='240' height='320' />"; } m getting the excepton in line invoke() and the thread is started like this objscreen = new screen(sock); thrdreceive=new Thread(new ThreadStart(receiveSocket)); thrdreceive.Start(); the class is same

    This code was posted by me...

    L 1 Reply Last reply
    0
    • V Vivek Vijayan

      create a control inside a thread and update it i need to create a thread and that thread creates a browser and update the image in browser each time it executes m geting nulref exception public void setWebBrowser() { Invoke(new EventHandler(workerAddBrowser)); } void workerAddBrowser(object sender, EventArgs e) { if (flag == 1) { browser.Refresh(); } browser = new WebBrowser(); Controls.Add(browser); browser.DocumentText =/* new Bitmap(File.Open("\\Program Files\\pic\\screen.jpg", FileMode.Open, FileAccess.Read));*/"<img src='file://\\Program Files\\syswifi\\pic\\screen.jpg' width='240' height='320' />"; } m getting the excepton in line invoke() and the thread is started like this objscreen = new screen(sock); thrdreceive=new Thread(new ThreadStart(receiveSocket)); thrdreceive.Start(); the class is same

      This code was posted by me...

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I can't tell why exactly you're getting a null reference exception since you didn't provide enough information; look at the line numbers, maybe it is because browser is still null. I suggest you read two of my articles: the latest one on cross-thread problems, and the one on Visual Studio tricks. See sig below. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      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