Application Focus Issue
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Application Focus Issue

Hybrid View

  1. #1
    Join Date
    Jul 2008
    Location
    Appleton, WI
    Posts
    23

    Unhappy Application Focus Issue

    I have a simple application that reads a large text file (290,000) lines, and for each line reorganizes the data into a set of objects. These objects are then written to an output file of about 4,000 lines.

    General Logic

    Get Input File from User
    Open File Using FileSystemObject
    For Each Line in File
    Sort Into Appropriate Objects
    Combine Statistical Data
    Get Output File from User
    Write Each Object/Subobject to OutPut File

    My problem arises during the file read. If focus is switched from the application during the read, the application will stop responding. I have reproduced this behavior both in and out of the dev environment. I am assuming that when the application loses focus, the system deprioritizes the process and that causes a problem.

    What I'd like is for the application to run like a background application, but allow for user input; I believe this will solve the focus problem. Does anyone know how to configure this? In addition, any other ideas on what is causing this would be helpful.
    Both the dev and production environment are Windows XP, Dev is SP3, Production is SP2. References to Microsoft Scripting Runtime and Common Dialog Control.

  2. #2
    Join Date
    Jul 2008
    Location
    Appleton, WI
    Posts
    23

    Re: Application Focus Issue

    ***Possible Solution***

    I have added DoEvents Commands to my file read loop and it seems to be working. Will know for sure tomorrow morning.

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,002

    Re: Application Focus Issue

    Depending on how quickly the loop fires, you don't want DoEvent firing every time. Create a counter, and add to it. Fire DoEvent every MOD 1000, or MOD 100. You want the HIGHEST number that keeps the app alive.

    Firing DoEvent events every time will actually slow your app down.

    Code:
    Dim ctr as Long ' > 32K possible
    ctr =1
    for each l in lines
      ctr=ctr+1
      if ctr Mod 100 = 0 Then DoEvents ' fires every 100 times, ONLY
      ' do other processing here
    next
    Last edited by dglienna; January 6th, 2009 at 07:18 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center