I have a windows service. In the OnStart method, I am performing some operation and if one of the operation fails, I want service to stop. In the Catch block I am writing below mentioned code:
var srvc = new System.ServiceProcess.ServiceController("Scv1", "localhost");
srvc.Stop();
srvc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped);
It does the job well but windows shows me a messagebox:
---------------------------
Services
---------------------------
The xxx service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
---------------------------
OK
---------------------------
Am I doing something wrong here? How do I suppress the messagebox?
I created a basic test service in C#, installed it on Windows 7, and then tried to start it.
using System.ServiceProcess;
public class MyService : ServiceBase
{
static void Main()
{
System.ServiceProcess.ServiceBase.Run( new MyService() );
}
protected override void OnStart( string[] args )
{
bool failed = true;
// Do stuff...
// Oops, we failed! Time to stop!
if( failed ) {
base.Stop();
return;
}
base.OnStart( args );
}
}
When it fails, yes, I do see the message box that you describe. This message box is not part of your service -- the Services window is showing that. If you were to open an administrator command prompt and type the following:
net start Scv1
Then you would see a text-based error message instead of a message box.
In either case, you are running a program that asks the SCM to start your service. Your service failed to start. That failure is reported back to the program. The program has decided to display an error message to inform the user. That is beyond your control.
You can actually check the event handler. It will intimate you the mistake you have done in the configuration file. Some syntax error in the configuration file will be the reason for this kind of message box.
Related
I am trying to work through connection issues at this stage of the app writing process. When the user leaves the game board, I call ...
void HelloWorld::onExit()
{
isMultiPlayer = CCUserDefault::sharedUserDefault()->getBoolForKey("MULTIPLAYER", false);
if(isMultiPlayer)
{
AppWarp::Client::getInstance()->disconnect();
CCUserDefault::sharedUserDefault()->setBoolForKey("MULTIPLAYER", false);
}
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
CCLayer::onExit();
}
From here, if I try to re-join the lobby, I get a
onConnectDone .. FAILED with unknown reason..session=0
Error in my log file. It seems like I need to wait around 5 minutes or so before this error disappears. Am I doing something wrong with my disconnect code, or is this kind of behavior the norm?
#PWiggin - this issue has now been fixed in our SDK update. You can pick the latest release from our GIT repo. Here is the link
https://github.com/shephertz/AppWarpCocos2DX/tree/master/V_1.5.1
In my j2me application, I receive above exception(java.lang.securityException not allowed to open connection). The flow of my function is like first I open socket for Receiving message in the constructor and then for sending SMS I open ports in the method body, on my phone MIDlet asks for permission to send SMS, if I press NO it shows security exception that SMS sending not denied, that's OK. But when being in the same MIDlet and performing this action second time it gives exception at the time of opening receiving port in the constructor as java.lang.securityException not allowed to open connection. At this time I yet not seen any permission asking for sending SMS for second time. My code for Constructor and SMS Sending is below:
//Constructor
public ServerContactRetriever(MainMidlet parent, Language lang) {
try {
this.language = lang;
this.parent = parent;
recvCon = (MessageConnection) Connector.open(RECV_URL); //open receiving port
recvCon.setMessageListener(this);
} catch (Exception ex) {
parent.dispErrorMessage(language.access_denied_disp);
parent.alertShow(language.access_denied_alert);
}
}
//METHOD
//Request restore contacts from server
private void sendRestoreRequest() {
try {
MessageConnection msgCon = (MessageConnection) Connector.open(SEND_URL);
TextMessage msg = (TextMessage) msgCon.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setAddress(SEND_URL);
msg.setPayloadText("set payload here");
msgCon.send(msg);
msgCon.close();
} catch (Exception ex) {
try {
parent.alertShow(language.sms_error_alert);
parent.dispErrorMessage(language.sms_error_disp);
recvCon.close();
} catch (Exception ex1) {
}
}
}
I am using WTK with MIDP 2.0.
Checking over Nokia Devices.
First I wonder there could be issue of closing MessageConnection port, but I tried that too and it shows the same error. Whereas about SMS send and I select NO, it works fine if I just try to send SMS and select NO as many times as I want and it still stays on the midlet without any exception. Thanks
There is no issue with closing MessageConnection. In some of the s40 and Symbian phones(like X2-02), the permission will be asked only once for one entire session. If you choose 'Yes', it wont ask you again while connecting second time. It will directly connect. Similarly, if you select 'No', while connecting first time, no connections will be allowed(securityException will be thrown) on every attempt to connect.
On some Nokia phones, you might see this option,
Select the application->Options->Application Access->Communication->
1. Ask Every time
2. Ask first time
3. Always allowed
4. Not allowed.
You can select the one that is appropriate to you.
If you don't want your application to seek permissions at all, you need to have your app signed by Manufacturer.
I did the mistaked and updated my pom.xml to selenium 2.18.0
now the UnhandledAlertException during an operation is the new feature:
Alert handling in Firefox and IE: Throwing UnhandledAlertException if an alert is present during an operation. The unhandled alert is also dismissed to mitigate repeat exceptions.
but if i call
driver = new InternetExplorerDriver();
it results in Modal dialog present Exception, because my current system needs proxy credentials, which are filled by a looping auto-it script (just in case somebody needs it):
Dim $arrTitle[2] = ["Authentification required", "Windows Security"]
While 1
For $sTitle In $arrTitle
If WinExists($sTitle) Then
WinActivate($sTitle);
Send("{HOME}");
Send("+{END}");
Send("{DEL}");
Send("user");
Send("{TAB}");
Send("{HOME}");
Send("+{END}");
Send("{DEL}");
Send("password");
Send("{ENTER}");
Sleep(1000)
EndIf
Next
Sleep(500)
WEnd
So how can I prevent this exception? If I simply
try { driver = new InternetExplorerDriver(); }
catch(UnhandledAlertException e) {}
i will receive a driver=null
Thanks for your time
If your system needs proxy credentials you should be able to pass this through with your desired capabilities into the driver.
see http://code.google.com/p/selenium/wiki/DesiredCapabilities#Proxy_JSON_Object on what to use.
I want to launch a local exe-file (without saving it to another location first) upon clicking on a link on a local html file.
It either needs to work in IE, Firefox, Chrome or Opera, I don't care. It's just for a presentation tomorrow.
It's simply not possible. If it was, it would be considered a security flaw and fixed. On Firefox within hours, on IE within some months.
UPDATE: You could try registering your custom protocol: http://openwinforms.com/run_exe_from_javascript.html
But I believe the browser will still prompt you whether you want to run the app.
I want to share my experience.
The accepted response says that it is not possible but it is quite possible indirectly.
If you want to execute an exe on a pc, it means that you have acces on this pc and you can install your exe on that machine.
In my case, I had to take a 3D scan from a 3D scanner via a web application. It seemed impossible at the beginning.
After lots of research, I found that we can send socket messages via javascript.
It means that if we had an application which listens a specific port, it can communicate with a website.
Let's explain how I did this.
In my web application, I created a javascript method like this :
function openCapron3DScanner(foot) {
$("#div-wait").show();
//Creates a web socket pointed to local and the port 21000
var ws = new WebSocket("ws://127.0.0.1:21000");
ws.onopen = function () {
//Sends the socket message to the application which listens the port 21000
ws.send(foot + "-" + #ProjectHelper.CurrentProject.Proj_ID);
};
ws.onerror = function myfunction() {
$("#div-wait").hide();
alert("Erreur connection scanner.");
}
ws.onmessage = function (evt) {
//Receives the message and do something...
var received_msg = evt.data;
if (received_msg == "ErrorScan") {
alert("Erreur scan.");
}
else {
refreshCurrentProject();
}
};
ws.onclose = function () {
$("#div-wait").hide();
};
};
And I created a windows forms application who listens the localhost and port 21000.
This application is hidden, only shown in icon tray.
The only thing to do is to add the application on windows startup via code on the first load to assure that the next restart of windows it will be executed and listen the port.
private static WebSocketServer wsServer;
static WebSocketSession LastSession;
private void Form1_Load(object sender, EventArgs e)
{
wsServer = new WebSocketServer();
int port = 21000;
wsServer.Setup(port);
wsServer.NewMessageReceived += WsServer_NewMessageReceived;
wsServer.Start();
}
private static void WsServer_NewMessageReceived(WebSocketSession session, string value)
{
if (value.StartsWith("ScanComplete-"))
{
//If the scan is ok, uploads the result to the server via a webservice and updates the database.
UploadImage(value);
//Sends a confirmation answer to the web page to make it refresh itself and show the result.
if (LastMacSession != null)
LastMacSession.Send("ScanComplete");
}
else if (value == "ErrorScan")
{
//If the C++ application sends an error message
if (LastMacSession != null)
LastMacSession.Send("ErrorScan");
}
else//call the 3D Scanner from the web page
{
LastSession = session;//Keeps in memory the last session to be able to answer via a socket message
//Calls the C++ exe with parameters to save the scan in the related folder.
//In could be don in this same application if I had a solution to consume the scanner in C#.
var proc = System.Diagnostics.Process.Start(#"C:\Program Files\MyProjectFolder\MyScannerAppC++.exe", projectID + " " + param);
}
}
I hope it will help.
Use System.Diagnostics.Process.Start() method.
protected void LinkButton1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("notepad.exe");
}
You'll have to use C#, but since that's on your post, it should work. You'll also need the full path, if the file is not in your environment path that's loaded in memory.
For a 'regular link' you'd still need to place this in an ASPX page.....
Click me
We're getting really fugly now though.
You can't run an exe file on a website. (First, if it's a Linux server, exe files won't run on it and second, if you're on a Windows server, your host would kill the program immediately. And probably terminate your account.)
That link (assuming it was Play Now!) will just allow your user to download the file. (C:\Program Files\World of Warcraft\ exists on your computer, but it doesn't exist on the web server.)
You could setup a custom protocol on your local OS, if it's Windows, in regedit.
Check out this and this.
Then you create a simple HTML page, and place a link, something like this :
Start!
Given that you registered your custom "presentation" protocol, and configured it correctly in the registry, the application should launch when you click that link.
I am at a complete loss as to why I am experiencing this problem. I am new to NServiceBus and have so far set up a dead simple 'server' which listens for messages sent by a web application. The server asks for custom initialisation (IWantCustomInitialization) and uses a custom builder for Castle Windsor 2.5.1. This custom builder is basically a copy of the one that comes with the NServiceBus source code, with two minor changes to move away from methods deprecated in Windsor 2.5.
Note that my code shares the container instance with NServiceBus.
The problem I experience is that every message sent by the web application is processed five (5) times by the server. The log files have five entries for each attempt, with the fifth attempt looking like this:
2011-03-28 16:04:10,326 [Worker.8] DEBUG NServiceBus.Unicast.UnicastBus [] - Calling 'HandleEndMessage' on NServiceBus.SagaPersisters.NHibernate.NHibernateMessageModule
2011-03-28 16:04:10,327 [Worker.8] DEBUG NServiceBus.Unicast.UnicastBus [] - Calling 'HandleEndMessage' on Server.NHibernateSessionMessageModule
2011-03-28 16:04:10,341 [Worker.8] DEBUG NServiceBus.Unicast.UnicastBus [] - Calling 'HandleError' on NServiceBus.SagaPersisters.NHibernate.NHibernateMessageModule
2011-03-28 16:04:10,342 [Worker.8] DEBUG NServiceBus.Unicast.UnicastBus [] - Calling 'HandleError' on Server.NHibernateSessionMessageModule
2011-03-28 16:04:10,344 [Worker.8] ERROR NServiceBus.Unicast.Transport.Msmq.MsmqTransport [] - Message has failed the maximum number of times allowed, ID=80cffd98-a5bd-43e0-a482-a2d96ca42b22\20677.
I have no indication why the message fails, and I don't know where to dig for more information/output.
The configuration 'endpoint' looks like this:
public void Init()
{
container = Windsor.Container;
NServiceBus.Configure.With().CastleWindsor251Builder(container).XmlSerializer().MsmqTransport().IsolationLevel(System.Transactions.IsolationLevel.Unspecified);
var masterInstaller = new NotificationServerInstaller();
masterInstaller.Install(container, null);
}
The message handler is, at this stage, really contrived, and looks like this:
public class NewUserMessageHandler : IHandleMessages<NotifyNewUserMessage>
{
private readonly IGetUserQuery _getUserQuery;
public NewUserMessageHandler(IGetUserQuery getUserQuery)
{
_getUserQuery = getUserQuery;
}
public void Handle(NotifyNewUserMessage message)
{
var result = _getUserQuery.Invoke(new GetUserRequest { Id = new Guid("C10D0684-D25F-4E5E-A347-16F85DB7BFBF") });
Console.WriteLine("New message received: {0}", message.UserSystemId);
}
}
If the first line in the handler method is commented out, the message is processed only once.
I have found some posts/threads on the web (including StackOverflow) which talk about similar issues, notably http://tech.groups.yahoo.com/group/nservicebus/message/5977 and Anyone using Ninject 2.0 as the nServiceBus ObjectBuilder? - but I haven't had any success in making my problem go away.
I'd be most obliged for any help. I'm a n00b at NServiceBus!
NServiceBus isn't handling it multiple times by default it will retry 5 times if an exception occurs, you can set this in a config file. Have you got distributed transactions turned on? Because you are committing to a database and you have an open transaction (the queue transaction) when you open another transaction it will try and upgrade it to a distributed transaction, I think that may be the issue. Have you run with the console app? You should see some out put on there.
I would recommend wrapping the body of the Handle method in a try/catch and add a break point to the catch and see what is wrong.
Once you work it out, remove the try/catch.