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. Mobile Development
  3. Mobile
  4. OpenFileDialog question (.Net C.F.)

OpenFileDialog question (.Net C.F.)

Scheduled Pinned Locked Moved Mobile
helpquestioncsharp
3 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.
  • H Offline
    H Offline
    Hurricane3000
    wrote on last edited by
    #1

    Hi all, I have a little (and I hope simple) problem with using of OpenFileDialog in a .Net C.F. aplication: When I open OpenFileDialog1 to choose the file to open/read, it remains active/visible for all time that the choosen file is reading. And as to reading the file sometime need also 4 minutes, I would like that OpenFileDialog1 remain visible only for time needed to choose the file, and immediately after it disappears to show again the main form. But I don't know to do it (OpenFileDialog1 doesn't accepts .close). Here a piece of my code: Private Sub MenuItem2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem2.Click openFileDialog1.InitialDirectory = "\My Documents" openFileDialog1.Filter = "wpt files (*.wpt)|*.wpt|txt files (*.txt)|*.txt" openFileDialog1.FilterIndex = 1 If openFileDialog1.ShowDialog() = DialogResult.OK Then myStream = openFileDialog1.FileName NomeFile = myStream Me.Text = "Waypoints Manager - " + myStream Using sr As StreamReader = New StreamReader(myStream) CountLines = 0 Do line = sr.ReadLine() If line = Nothing Then Exit Do CountLines = CountLines + 1 Loop Until line Is Nothing sr.Close() End Using Can someone help me please? Thanks Ignazio

    J 1 Reply Last reply
    0
    • H Hurricane3000

      Hi all, I have a little (and I hope simple) problem with using of OpenFileDialog in a .Net C.F. aplication: When I open OpenFileDialog1 to choose the file to open/read, it remains active/visible for all time that the choosen file is reading. And as to reading the file sometime need also 4 minutes, I would like that OpenFileDialog1 remain visible only for time needed to choose the file, and immediately after it disappears to show again the main form. But I don't know to do it (OpenFileDialog1 doesn't accepts .close). Here a piece of my code: Private Sub MenuItem2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem2.Click openFileDialog1.InitialDirectory = "\My Documents" openFileDialog1.Filter = "wpt files (*.wpt)|*.wpt|txt files (*.txt)|*.txt" openFileDialog1.FilterIndex = 1 If openFileDialog1.ShowDialog() = DialogResult.OK Then myStream = openFileDialog1.FileName NomeFile = myStream Me.Text = "Waypoints Manager - " + myStream Using sr As StreamReader = New StreamReader(myStream) CountLines = 0 Do line = sr.ReadLine() If line = Nothing Then Exit Do CountLines = CountLines + 1 Loop Until line Is Nothing sr.Close() End Using Can someone help me please? Thanks Ignazio

      J Offline
      J Offline
      Joel Ivory Johnson
      wrote on last edited by
      #2

      Without looking at your code I can tell what's going on since it is such a frequently occurring question. The problem you are encountering is intrinsic to applications with single threads. The OpenFileDialog isn't still active. It is closed. However, your application hasn't redrawn it self so the last image that was on the screen remains visible until it does. Right now you are reading the file on your primary thread, and while that primary thread is busy reading the file it does not have the opportunity to redraw the main window. When the read operation completes then the application can use that thread to redraw the main interface. To prevent that behaviour you will need to read your file on a secondary thread so that the primary thread is still free to redraw the main interface. This concept can be applied to both desktop and mobile applications written with managed and native code. Please read the following for a more complete explanation of the problem you are encountering and the solution. Give Your .NET-based Application a Fast and Responsive UI with Multiple Threads

      Joel Ivory Johnson

      Meet my dev team: RDA Architecture Evangelist Team Blog

      My site: J2i.net

      modified on Sunday, December 14, 2008 4:51 PM

      H 1 Reply Last reply
      0
      • J Joel Ivory Johnson

        Without looking at your code I can tell what's going on since it is such a frequently occurring question. The problem you are encountering is intrinsic to applications with single threads. The OpenFileDialog isn't still active. It is closed. However, your application hasn't redrawn it self so the last image that was on the screen remains visible until it does. Right now you are reading the file on your primary thread, and while that primary thread is busy reading the file it does not have the opportunity to redraw the main window. When the read operation completes then the application can use that thread to redraw the main interface. To prevent that behaviour you will need to read your file on a secondary thread so that the primary thread is still free to redraw the main interface. This concept can be applied to both desktop and mobile applications written with managed and native code. Please read the following for a more complete explanation of the problem you are encountering and the solution. Give Your .NET-based Application a Fast and Responsive UI with Multiple Threads

        Joel Ivory Johnson

        Meet my dev team: RDA Architecture Evangelist Team Blog

        My site: J2i.net

        modified on Sunday, December 14, 2008 4:51 PM

        H Offline
        H Offline
        Hurricane3000
        wrote on last edited by
        #3

        Thank you very much Joel! Your posts are precise and reliable as usual. I will follow your advice. But While I was trying to resolve the problem, I made this simply modify to the code: I placed the OpenFileDialog1 code and the file reading code in 2 different Sub, and in the first line of reading Sub I added ME.Refresh() statement. It seems that this modify works and the OpenFileDialog1 disappears before the file is read (as I desired). Ignazio

        modified on Monday, December 15, 2008 4:35 PM

        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