• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

Make GUI Accessible While Having a Background Process. 500Pts Urgent

I have a MDI form and few childs.

In one menu I have this SQL Script Executing

Function SetFreight() As Boolean
conOPEN
con.Execute ("Update PROD SET PFType = (select CASE DFType WHEN  'W' then 'W' WHEN '%' THEN '%' WHEN  'F' THEN 'F' End From DEPT Where ProdDepID = DeptID), Freight = (select CASE DFType WHEN  'W' then ((Weight / 1000.0) * FValue) WHEN  '%' THEN ((FValue * RRP) / 100.0) WHEN  'F' THEN FValue End From DEPT Where ProdDepID = DeptID)")
con.Close
SetFreight = True
End Function


Total Time of execution for this script take about a minute.

I notice While it execution the GUI goes freeze and stop responding. Also For this time Whole window become white.
I want to display a message " please stand by"  untill SetFreight = True.
How Can I do this?
Can I Use DoEvent in Here?

Udana
0
udanabanana
Asked:
udanabanana
  • 7
  • 3
  • 3
  • +2
1 Solution
 
JackOfPHCommented:
try puting doevents:

Function SetFreight() As Boolean
x = doevents()
conOPEN
con.Execute ("Update PROD SET PFType = (select CASE DFType WHEN  'W' then 'W' WHEN '%' THEN '%' WHEN  'F' THEN 'F' End From DEPT Where ProdDepID = DeptID), Freight = (select CASE DFType WHEN  'W' then ((Weight / 1000.0) * FValue) WHEN  '%' THEN ((FValue * RRP) / 100.0) WHEN  'F' THEN FValue End From DEPT Where ProdDepID = DeptID)")
con.Close
SetFreight = True
End Function

0
 
JackOfPHCommented:
Function SetFreight() As Boolean
x = DoEvents() `***************** here is the doevents()

conOPEN
con.Execute ("Update PROD SET PFType = (select CASE DFType WHEN  'W' then 'W' WHEN '%' THEN '%' WHEN  'F' THEN 'F' End From DEPT Where ProdDepID = DeptID), Freight = (select CASE DFType WHEN  'W' then ((Weight / 1000.0) * FValue) WHEN  '%' THEN ((FValue * RRP) / 100.0) WHEN  'F' THEN FValue End From DEPT Where ProdDepID = DeptID)")
con.Close
SetFreight = True
End Function
0
 
Naveen SwamyCommented:
use adAsyncFetchNonBlocking

indicates that the main thread never blocks while retrieving. If the requested row has not been retrieved, the current row automatically moves to the end of the file. If you open a Recordset from a Stream containing a persistently stored Recordset, adAsyncFetchNonBlocking will not have an effect; the operation will be synchronous and blocking. adAsynchFetchNonBlocking has no effect when the adCmdTableDirect option is used to open the Recordset.

http://www.w3schools.com/ado/met_conn_execute.asp
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
udanabananaAuthor Commented:
navstar16
Im not using ado I guess.. Im using SQLite www.sqlite.org
0
 
udanabananaAuthor Commented:
JackOfPH
 nah it didnt help, sorry
any other ideas?
0
 
junglerover77Commented:
Well, if your "sqlite" doesn't support asynchronism processing, there is no way to achieve your goal in a single VB application, because VB doesn't support real Multi-Thread.

But there is an alternative way to do this. Although it sounds strange and a little complicated, it would work.

1. Build an seprated application with a single dialog box showing message " please stand by";
2. Before you execute your SQL query, shell the message application, then hide the main application, then execute SQL;
3. The message application would check a flag "completed" every second. This flag can be stored in Registry, or an INI file; If the value of this flag becomes true, the message application activate the main application, then terminate itself;
4. When the SQL query is completed, the main application will set the "Completed" flag to "True", then show itself.

Regards,
Jungle
0
 
udanabananaAuthor Commented:
Jungle,
Sounds Inovating Well is it posible to see some basic source codes?

about SQLite and asynchronism ; Is this support by ADO Component?
just to make sure cuz Im using LITEX to connect SQLite Database.

Udana
0
 
lojk.Net and Infrastructure ConsultantCommented:
Not quite true about VB not being multithreaded. VB.NET definintely does and VB6 can be persuaded to (try pushing your code into an activex dll wrapper and changing its threadingmodel from single threaded and accessing your dll from your app..)

Are you using VB.Net or VB6?
0
 
udanabananaAuthor Commented:
lojk
Im using VB6, Im not a expert and havent tried those things before... if you can guide me to a get more resources that would be great
Udana
0
 
junglerover77Commented:
Just put a label and a timer control on a Form, then past the following code into it:

Option Explicit

Private Sub Form_Load()
    Label1.Left = 0: Label1.FontSize = 18: Label1.AutoSize = True
    Label1.Caption = "Processing... Please wait."
    Timer1.Interval = 500
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Dim strCompleted As String
    strCompleted = GetSetting("MyApp", "MySection", "Completed", "False")
    Label1.Visible = Not Label1.Visible
   
    If strCompleted = "True" Then
        Timer1.Enabled = False
        Unload Me
    End If
End Sub

Save this Project and compile it as Project1.exe. Put this exe into the same folder of your application.

Then, In your application, in the procedure you execute the query, add the following code:

    Call SaveSetting("MyApp", "MySection", "Completed", "False")    
    Call Shell(App.Path + "\Project1.exe", vbNormalFocus)
    Me.Hide

    'Do your query here!

    Call SaveSetting("MyApp", "MySection", "Completed", "True")    
    Me.Show
    Me.Setfocus

Regards,
Jungle
0
 
udanabananaAuthor Commented:
Jungle,
Good it work perfectly. But I have 2 issues. Thank you  verymuch for your help.
1 I want Project1.exe can be executed using only from my program. It shouldn't be a self executable program.
2 It should be on top of my program. or atleast top of all the programs.

Also I dont want to hide my program so I just use enable and disable

So how can we provide a solution for above two issues?
Regards
Udana

0
 
junglerover77Commented:
Hi Udana,

Your first goal is achievable. Just add the following code to the form of Project1.exe:
Private Sub Form_Activate()
    If Command <> "nfsldnflasnlnzkxflzndflk" Then Unload Me
End Sub

and change you code of calling Project1.exe to:
   Call Shell(App.Path + "\Project1.exe nfsldnflasnlnzkxflzndflk", vbNormalFocus)

So, when the user tries to run project1.exe, it will terminate itself immediately.

Your second goal is still achievable. You can just use the API "SetWindowPos" to set this window to a TOPMOST window.

But your third goal is a "Mission: Impossible". If you don't hide your program, it will not response to WM_PAINT message when executing your query, so the whole window will still turn WHITE (Even if you disable it). Only the window of Project1 will not turn white.
0
 
lojk.Net and Infrastructure ConsultantCommented:
just a quick question (im going to do some tests and get back to you on vb6 multithreading later) can you not use VB.Net?

The benefits go way beyond easy multithreading....
0
 
lojk.Net and Infrastructure ConsultantCommented:
Heres a sample project on PSC that will get you going....

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=14479&lngWId=1

but ill see if i can knock up some code for you later...
0
 
udanabananaAuthor Commented:
Thanks everybody for great help...
I guess jungle should earn the points though...

Udana
0
 
udanabananaAuthor Commented:
----But your third goal is a "Mission: Impossible". If you don't hide your program, it will not response to WM_PAINT message when executing your query, so the whole window will still turn WHITE (Even if you disable it). Only the window of Project1 will not turn white.----

I tested this and i wont turn white...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now