|
Hi Justim,
I haven't done it myself, but my understanding is you can demote a Form to the equivalent
of a Panel by setting its Form.TopLevel Property false; once you do that, you can give it
a Parent or add it to some other Control's Controls collection. So that should do it.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Form2 form = new Form2();
form.FormBorderStyle = FormBorderStyle.None;
form.TopLevel = false;
this.tabPage1.Controls.Add(form);
form.Show();
|
|
|
|
|
In the process of learning how to write a Windows service with .Net, I've noticed the the service will shutdown if there's nothing going on, or if it can't respond to the periodic Task Manager "are you alive?" messages.
What I've ended up doing is including a keep-alive thread in every service that contains a while loop that sleeps for four seconds at a time and then cycles through the while again. Is this a necessary step, or am I doing something fundamentally wrong in my service code?
I've also found that if I have a thread (the one and only thread) that sleeps longer than four seconds while it's waiting for something to happen, it will stop the service because Windows thinks it's "not responding". This means that the thread needs to consume unnecessary cpu cycles by stopping every four seconds and determining whether or not sufficient time has passed to kick off further processing.
Lastly, event the presence (in the service) of a running file watcher is enough to keep the service alive.
Am I just missing something?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi John,
Maybe your OnStart is failing, that's the reason of the error.
If you create a new Service project, just add the installer. For example, I created a simple service (WindowsService1), I didn't add any code yet. And added the installer to it.
installutil.exe WindowsService1.exe
Maybe your service is throwing some exception, I put in System.Threading.Thread.Sleep(20000); in OnStart and it didn't timeout.
God bless,
Ernest Laurentin
|
|
|
|
|
If I don't put a keep-alive thread in the code, the service starts automatically and then presnts this message (or something similar):
Nothing to do. Service is stopping.
The only way to keep it from doing that is to put in a keep-alive thread. I've tried using timers and/or file watchers, and it always termiates if I'm not running a thread with a while loop to keep it from stopping on its own.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hmm...never seen that. Did you use an installer class to install the service?
I usually configure service as LocalSystem.
OK. no clue.
God bless,
Ernest Laurentin
|
|
|
|
|
Yeah, I have an installer class, but due to the nature of the service, we had to install it as a specific user (versus Local System) - I don't know why though.
EDIT - I just found out why we have to do that - it's because the service has to communicate with another machine on the network that has user-specific permissions. We can't use any of the built in user accounts, and instead have to install under a user account that has permissions on the remote machine.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I haven't had that problem.
Each of my Windows Services contains a Timer and the Timer_Elapsed handler is what performs the function of the Service. I have Services with Timers set to cycle anywhere from every fifteen seconds to every ten minutes. I can't imagine a Service without a Timer. All the OnStart method does is start the Timer. The OnStop method stops the Timer.
|
|
|
|
|
A timer event isn't the same as a Sleep. When your app Sleeps, it doesn't respond to any system messages. Task manager periodically sends out a message to all running processes and if they don't respond within 5 seconds, the task manager thinks they're hung up. In the case of a service, the TM appears to stop it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
|
I tried both a timer and a file watcher before resorting to a thread.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
(The Timer's Elapsed method executes in its own thread.)
|
|
|
|
|
Hello,
VS 3.5
I have created a simple C++ DLL, and I want to use this in my C# program.
However, I am getting a Can't find PInvoke DLL 'TEST_SIP.dll
I have placed the DLL in my debug folder where my C# program is executed from. I am not sure if that is the correct place to put it.
Not sure where I am going wrong with this one.
many thanks for any suggestions,
Steve
Code in my C#
<br />
[DllImport("TEST_SIP.dll")]<br />
public static extern double Add(double a, double b);<br />
<br />
private void btnLogin_Click_1(object sender, EventArgs e)<br />
{<br />
string msg = SendData("Hello how are you");
MessageBox.Show(msg);<br />
}<br />
C++ header
<br />
#include <iostream><br />
<br />
namespace TEST_SIP<br />
{<br />
class TEST_SIP_Phone<br />
{<br />
public:<br />
static _declspec(dllexport) double Add(double a, double b);<br />
static _declspec(dllexport) double Subtract(double a, double b);<br />
static _declspec(dllexport) double Multiply(double a, double b);<br />
static _declspec(dllexport) double Divide(double a, double b);<br />
static _declspec(dllexport) std::string SendData(std::string data);<br />
};<br />
}
C++ Functions
<br />
#include "TEST_SIP.h"<br />
#include <stdexcept><br />
#include <cctype><br />
<br />
using namespace std;<br />
<br />
namespace TEST_SIP<br />
{<br />
double TEST_SIP_Phone::Add(double a, double b)<br />
{<br />
return a + b;<br />
}<br />
double TEST_SIP_Phone::Subtract(double a, double b)<br />
{<br />
return a - b;<br />
}<br />
double TEST_SIP_Phone::Multiply(double a, double b)<br />
{<br />
return a * b;<br />
}<br />
double TEST_SIP_Phone::Divide(double a, double b)<br />
{<br />
if(b == 0)<br />
{<br />
throw new invalid_argument("b cannot be zero!");<br />
}<br />
<br />
return a / b;<br />
}<br />
std::string TEST_SIP_Phone::SendData(std::string data)<br />
{<br />
return data; <br />
} <br />
}<br />
|
|
|
|
|
Try this: Simple Dll (Build this: cl /LD SimpleDll.cpp )
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpReserved )
{
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
extern "C" __declspec(dllexport)
double Add(double a, double b)
{
return a + b;
}
extern "C" __declspec(dllexport)
double Subtract(double a, double b)
{
return a-b;
}
extern "C" __declspec(dllexport)
double Multiply(double a, double b)
{
return a*b;
}
extern "C" __declspec(dllexport)
double Divide(double a, double b)
{
if ( b != 0 )
return a/b;
return -999999999999999999999.0;
}
Hello world application (build: csc /t:exe HelloWorld.cs)
using System;
using System.Runtime.InteropServices;
namespace HelloWorld
{
class Hello
{
[DllImport("SimpleDll.dll", EntryPoint="Add", CallingConvention=CallingConvention.Cdecl)]
public static extern Double Add(Double a,Double b);
[DllImport("SimpleDll.dll", EntryPoint="Subtract", CallingConvention=CallingConvention.Cdecl)]
public static extern Double Subtract(Double a,Double b);
[DllImport("SimpleDll.dll", EntryPoint="Multiply", CallingConvention=CallingConvention.Cdecl)]
public static extern Double Multiply(Double a,Double b);
[DllImport("SimpleDll.dll", EntryPoint="Divide", CallingConvention=CallingConvention.Cdecl)]
public static extern Double Divide(Double a,Double b);
static void Main()
{
System.Console.WriteLine("Add: {0}", Add(3,4));
System.Console.WriteLine("Subtract: {0}", Subtract(7,4));
System.Console.WriteLine("Multiply: {0}", Multiply(3,4));
System.Console.WriteLine("Divide: {0}", Divide(12,4));
}
}
}
God bless,
Ernest Laurentin
modified on Thursday, March 6, 2008 1:09 PM
|
|
|
|
|
steve_rm wrote: [DllImport("TEST_SIP.dll")]
It may be looking only in the Windows directory for it.
Maybe you need to provide the full path?
|
|
|
|
|
Hi
I want to know :
in briefly, What's Mean this sentence : (C# is strongly typed language) ?
thanks
|
|
|
|
|
Gosh - that's such a hard one to find any answers on. If only there existed some repository of information that you could search. Click[^].
|
|
|
|
|
I've run out of sarcasm for such questions, you seemingly have a never-ending supply . What I need is a banging my head against a brick wall smiley
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Phannon wrote: you seemingly have a never-ending supply
It's such a curse. The banging the head smiley is a good idea though.
|
|
|
|
|
Pete O'Hanlon wrote: It's such a curse
I have to say that since living in Glasgow I'm now generally more cynical and sarcastic that I ever was. I suppose working for a company for just under 2 years and with 3 name changes (and a fourth on the way) doesn't help.
|
|
|
|
|
Hmmm. Perhaps it was my time in Glasgow that turned me into the hollowed out bitter shell... Nope, I've always been sarcastic.
|
|
|
|
|
Phannon wrote: I've run out of sarcasm
You shouldn't, you should recycle rather than waste. Much nicer for the environment
(excluding the OP of course).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
It means you have to type all of your own code manually.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
No, no, John, it means you must exhibit brute strength while pressing the keys on the keyboard as you type in your code.
|
|
|
|
|
Judah Himango wrote: it means you must exhibit brute strength while pressing the keys on the keyboard as you type in your code
Actually reminds me of when I learned to type. My dad had this big old mechanical typewriter that required a lot of effort (especially for a 7 year old) to push the keys. (I never got the hang of using my pinky though - I didn't have the strength and the bad habit of using my ring finger is still with me.)
|
|
|
|