Form-less program...

Tex8503

Active Member
Licensed User
Longtime User
Hey Folks,
I'm trying to write a small PC based app that copies a file on a regular basis. I'm trying to make it as invisible as possible as I don't want users messing with it.

It basically should poll looking for a file and copy it if it exists. I decided I wanted a system tray icon though - So I'm using ControlsExDesktop.dll with the notifyicon and a context menu so a user could potentially quit if necessary.

The problem is that if I run a looped action, it freezes the GUI and I can't actuall click the context menu on the icon in the system tray. I thought the solution might be to run the check for the file it's looking for as its own thread using the threading library - leaving the main thread free for the GUI actions - but if i do that, then because there's no form action or regular looped action, the application closes - but if I run a looped action to keep it open, I'm still going to have issues.

Any ideas?
 

taximania

Well-Known Member
Licensed User
Longtime User

Can't you use a Timer to check your file is there ?
 

Tex8503

Active Member
Licensed User
Longtime User
Can't you use a Timer to check your file is there ?

I would - but it won't keep the application running without a form open. I basically want to run the timer without a form.

http://www.b4x.com/forum/questions-help-needed/441-impossible-make-app-without-form.html#post1981
That was posted before with the following code:
B4X:
Sub App_Start
InitBitsAndBobs  'General code to run once
...
...
Begin: 'Label to loop round
...
...
... 'Program statements If this happens do something else etc
...
...
GoTo Begin
End Sub
and this code works - but you can't interact with the GUI as the loop ties up the thread.
 

mjcoon

Well-Known Member
Licensed User
I would - but it won't keep the application running without a form open. I basically want to run the timer without a form.

Why? A blank form isn't going to offer much interaction. (I wonder how small the screen size can be set?) How about just minimising the program?

Mike.
 

Tex8503

Active Member
Licensed User
Longtime User
Taximania - Might try that. Thanks! I'll let you know how it goes.

mjcoon - Because I shouldn't need to have a blank form on screen for a program that isn't going to let the user do anything. I'd just as soon run this app as a service if possible

No sense in showing a GUI when there's no UI for the user to interact with.
 

agraham

Expert
Licensed User
Longtime User
Basic4ppc needs at least one Form in order to have a message loop. Without a message loop to drop into the main thread terminates when it returns from running App_Start.

Running loops and DoEvents is a Bad Thing in an event driven environment as it burns processor cycles stopping the CPU getting to its idle loop where the power saving measures lie so shortening battery life.
 

mjcoon

Well-Known Member
Licensed User
Running loops and DoEvents is a Bad Thing in an event driven environment as it burns processor cycles stopping the CPU getting to its idle loop where the power saving measures lie so shortening battery life.

Or, formless is to avoid, as the Bible nearly says...

The original query related to a "small PC based app", so unless for a lap-top the battery aspect may not be significant. But a supposed background program that consumes all the CPU it can get is definitely a Bad Thing and tantamount to a Denial Of Service attack!

Mike.
 

Zenerdiode

Active Member
Licensed User
Please try the following program, I think it does what you want. If you add a project icon; it will become the Notification Area icon.
 

Attachments

  • MinimisedApplication.sbp
    1.8 KB · Views: 235

taximania

Well-Known Member
Licensed User
Longtime User
Nice work Zener. I re-compiled it for the PC, and added a Msgbox in the timer1.tick to fire every 30 seconds.
Works a treat.

It hasn't slowed my laptop down.
No fans kicking in. 'Task Manager' showing little usage.
I'm gonna have to kill the app now though.
It's annoying LOL
 

Tex8503

Active Member
Licensed User
Longtime User
Zenerdiode - This issue came up again and I saw your reply - I'm gonna give your code a shot. Thank you for sharing!
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…