|
The simple way is to run it via a Scheduled Task instead.
|
|
|
|
|
Thanks PIEBALD. I think thats a great idea.
|
|
|
|
|
This p/invoke works
[DllImport("Kernel32.dll")]
public static extern int AllocConsole();
[DllImport("Kernel32.dll")]
public static extern int FreeConsole();
...
System.Threading.Thread.Sleep(3000);
FreeConsole();
System.Threading.Thread.Sleep(3000);
AllocConsole();
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
So, in the example - its going to allocate the console for 3 sec and then free it for 3 sec?
In my Main - I have the following:
<br />
Timer myTimer = new Timer();<br />
myTimer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );<br />
myTimer.Interval = 900000;<br />
myTimer.Start();<br />
while (Console.Read() != 'q')<br />
{<br />
;<br />
} <br />
How do I incorporate System.Threading.Thread.Sleep here. I'd have to get rid of the timer?
Thanks.
|
|
|
|
|
The Sleep(3000) in my example just demonstrated it -
in my case I was testing from a console app so the console
was already open when the sample code was hit.
I let it show for 3 seconds, hide it for three seconds,
then show it again.
You could use the same code in a GUI app but you'd need to
call AllocConsole() first to show the console window.
The Sleep() was to demonstrate that it works - you shouldn't be using
Sleep() - you have a timer
AllocConsole() shows the console, FreeConsole() hides it.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks, Great - Mark.
In my while loop, I called the AllocConsole and FreeConsole, but my console still stays.
Also, I was actually trying to synchronize it with the processing. So, its like -
1) After 15 seconds has elapsed, the console pops up - the program does the processing.
2) As soon as the processing completes - the console goes away.
3) Repeat.
Thanks for all your help.
|
|
|
|
|
Ekjon wrote: In my while loop, I called the AllocConsole and FreeConsole
Then what's the timer for?
Ekjon wrote: After 15 seconds has elapsed,
Is that controlled by the timer? If I did the math
correctly, your timer is at 15 MINUTE intervals, not 15 seconds.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thats right.
The reason is - I was testing it and didn't want to wait for 15 minutes every time, so I set it to 90000 which is 1.5 minute.
So, the problem is: the console just stays, while it should go away when the FreeConsole() is called.
Thanks.
|
|
|
|
|
hmm I'm not sure what's happening. Without your code it's tough to debug
All I know is I tested the code I posted in a C# console app.
If you make a C# console app that does the following, does it work?
[DllImport("Kernel32.dll")]
public static extern int AllocConsole();
[DllImport("Kernel32.dll")]
public static extern int FreeConsole();
static void Main(string[] args)
{
Console.WriteLine("Hi from the first console");
System.Threading.Thread.Sleep(3000);
FreeConsole();
System.Threading.Thread.Sleep(3000);
AllocConsole();
Console.WriteLine("Hi from the second console");
Console.WriteLine("\r\n\r\n");
Console.WriteLine("Press Enter to end...");
Console.ReadLine();
}
If that works, then what are you doing different in your code?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I did the following and it's working fine now.
[DllImport("Kernel32.dll")]public static extern int AllocConsole();<br />
[DllImport("Kernel32.dll")]public static extern int FreeConsole();<br />
static void Main(string[] args)<br />
{<br />
System.Timers.Timer myTimer = new System.Timers.Timer();<br />
myTimer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );<br />
myTimer.Interval = 90000;<br />
myTimer.Start();<br />
while (true)<br />
{ <br />
;<br />
}<br />
}<br />
public static void DisplayTimeEvent( object source, ElapsedEventArgs e )<br />
{<br />
AllocConsole();<br />
FreeConsole();<br />
}<br />
Before...I was trying to call them in the wrong place.
Thanks so much.
|
|
|
|
|
Cool
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Any experience or ideas printing labels from Dot.net (C#) - what's the best way
Current project uses 2 column/5 row and 3 column/10 rows labels. TIA
Tom
|
|
|
|
|
Hi,
Both Crystal and Reporting Services can be used. Maybe it's a little bit easier with crystal (mainly creating the layout).
However, if you can use MS Word, it's even simpler with it using mail merge. In that case c# code creates the data and delivers it to Word and all of the layout is done using Word. This method is perhaps the easiest and as a bonus, the layout can be modified independently from the program.
Hope this helps,
Mika
|
|
|
|
|
|
Sounds like a plan to me especially if you don't see any downsides in current solution.
Mika
|
|
|
|
|
try the SQL Reproting Service
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
hy everyone!
i do have some problems with the process.start() methode.
i want to start the following command via the process.start()
"C:\Program Files\Acrobate\Reader 8.0\Reader\AcroRd32.exe" /h /t "C:\sourcedir\somefile.pdf" "printer001" (sure it's not the correct syntax here, but it's readable this way)
when i try to start this code in command line then it works fine, but when i add it to the process.start() methode, it either does nothing or it throws an exception "there is/are invalid path/s"
I added full access to the sourcedir, so access problems shouldn't be the reason.
when i just try to start acrobate as parameter (so e.g.
System.Diagnostics.Process.Start("\"C:\\Program Files\\Acrobate\\Reader 8.0\\AcroRd32.exe\"");
, it works and it start acrobate as a process. when i just add the file including the dirinfo e.g.
System.Diagnostics.Process.Start("\"C:\\sourcedir\\somefile.pdf\"");
, it accepts it as well. but it does not work using the whole string above.
i also tried to use the startinfo object with all it's parameters, but it didn't work neither.
does anyone of you have an idea? I don't think it's a problem because of access rules, because why would the acrobate start if there were some??
thanks!
stephan.
|
|
|
|
|
Hi,
What if you try:
System.Diagnostics.Process.Start("C:\\Program Files\\Acrobate\\Reader 8.0\\AcroRd32.exe", "\"C:\\sourcedir\\somefile.pdf\"");
Mika
|
|
|
|
|
is there a difference in mering it to one string or to seperate it with a comma??
and is there a chance to get it start with the parameters and the printer this way?
|
|
|
|
|
Just wondering is there a typo. Should there be folder Reader after Reader 8.0? Take a look at the paths you posted
C:\Program Files\Acrobate\Reader 8.0\Reader\AcroRd32.exe
C:\\Program Files\\Acrobate\\Reader 8.0\\AcroRd32.exe
|
|
|
|
|
yeap, this is a typo, sorry.
the correct path is C:\\Program Files\\Acrobate\\Reader 8.0\\AcroRd32.exe in every example.
|
|
|
|
|
No problem That solved the problem?
|
|
|
|
|
nope, it's just a typo in here!
|
|
|
|
|
Ok, next steps could be:
- any info in stack of the exception
- is the exception type of Win32Exception
One possibility is usage rights as you mentioned. You could try to move the pdf to another place (for example temp where you would not have problems with rights)
Another thing is that is it possible that Acrobat is actually giving the error and it's only reported through .net framework.
I may be totally off the track at this time of the day (1 AM local time) and need to get some sleep, but I'll check on this again tomorrow
Mika
|
|
|
|
|
Acrobat really has the "e" on the end on your system?
This worked fine for me:
System.Diagnostics.Process.Start("\"C:\\Program Files\\Adobe\\Reader 8.0\\Reader\\AcroRd32.exe\"", "");
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|