I've recently finished creating a WPF application where I used the InstallShield Limited Edition Project for the setup and deplotment, to create an exe file.
This was done so I could install it where it was needed, however I have run into a snag shortly after installing the program on another PC.
The program is installed correct (I believe), but I've run into the problem that the timer I am using. (System.Timers.Timer) is not firing and/or working on these other PC's that are not development PC's (Ie. does not have VS15/17).
The program only works when used on a Development PC.
I've tried to figure out why it wouldnt work and I've not been able to figure out what they are missing for them to work.
Both the PC's have the Microsoft Frameworks they should (4.5 and above), so I've run out of ideas.
This line is placed inside the constructor for the MainWindow
crashCheckTimer = new System.Timers.Timer(_waitTime);
The SetTimer method
private void SetTimer(bool start)
{
// Hook up the Elapsed event for the timer.
try
{
crashCheckTimer.Enabled = start;
crashCheckTimer.AutoReset = true;
crashCheckTimer.Elapsed += CrashCheckEvent;
}
catch (Exception ex)
{
logBuilder.ErrorLogCreation(ex, DateTime.Now, "SetTimer", NumberOfFilesToKeep);
throw;
}
}
The CrashCheckEvent just runs some code, but is never called on the non dev pc's
Update:
I changes the Timers.Timer to Dispatcher.Timer on the advice of a co-worker and that have seemingly fix my issue with getting the timer to fire again.
Related
Note that this article is not a duplicate. I am having a different issue.
My client computer cannot see WebView2 content in any WPF project. After some debugging effort, I pinpointed it to EnsureCoreWebView2Async call. I sent him a brand new WPF project with these code:
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
this.wv.CoreWebView2InitializationCompleted += this.Wv_CoreWebView2InitializationCompleted;
MessageBox.Show("EnsureCoreWebView2Async is about to run");
await this.wv.EnsureCoreWebView2Async();
MessageBox.Show("EnsureCoreWebView2Async finished");
}
private void Wv_CoreWebView2InitializationCompleted(object? sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
{
if (e.InitializationException is not null)
{
MessageBox.Show("EnsureCoreWebView2Async has exception: " + e.InitializationException);
}
else
{
MessageBox.Show("EnsureCoreWebView2Async successful: " + e.IsSuccess);
this.wv.CoreWebView2.Navigate("https://www.example.com");
}
}
I even tried to wrap the code in Window_Loaded inside a Dispatcher.Invoke() call to make sure it's executed in a UI thread but it has the same result.
On all other computers that I tested (Windows 11 and 10), we see all messages that are supposed to show but on his computer (Windows 10, latest update) only "EnsureCoreWebView2Async is about to run" is showed. After that nothing happens at all. He has VS2022 installed and I tried debugging and stepping over EnsureCoreWebView2Async never ends.
We tried reinstalling .NET 6. Attempting to run WebView2 installation (Evergreen Bootstrapper download from official website) results in message saying it's already installed.
I tried compiling on my computer and sent over to his computer, his computer would not show the website (call never finishes). I asked him to compile on his side and send over to me, my computer shows up the website just fine with all the messages showed so I am sure it's not because of the compiler/compiling environment.
So far I cannot find any second computer that has the same issue, but according to our Windows Store review, someone also has the issue (their UI is blank). I cannot find out what is causing the problem. Please advise us on how to debug this issue.
As for my case, the issue is resolved by uninstalling his WebView2 Runtime (from Control Panel) and reinstall it, every works now. Guess now we will never know what is the cause.
I am trying to do some kind of Installer where i need to install a WinService.
What I currently do is adding the Service.exe as Resource to my Installer Project, then write all bytes of it to a specific folder.
After successfully writing the file to a specified folder, i install the service using ManagedInstallerClass.InstallHelper
The problem i've with it now is that the ManagedInstallerClass.InstallHelper is somehow locking the Service executable, so i cannot delete/overwrite the file (from outside or inside the program), because it's blocked while the Installer Application is running, beginning from first ManagedInstallerClass.InstallHelper call on the Service file.
Here is my code which causes this problem.
private void button1_Click(object sender, EventArgs e)
{
try
{
UninstallAndStopServiceIfExist("RDPBFP_Service");
}
catch (Exception)
{
MessageBox.Show("Service not running, so cannot stop it!");
}
Thread.Sleep(1000);
//File.Delete(#"C:\RDPBFP\RDP-Bruteforce-Protector_Service.exe");
Directory.CreateDirectory(#"C:\RDPBFP");
File.WriteAllBytes(#"C:\RDPBFP\RDPBFP_Service.exe", Properties.Resources.RDPBFP_Service);
try
{
ManagedInstallerClass.InstallHelper(new string[] { #"C:\RDPBFP\RDPBFP_Service.exe" });
}
catch (Exception i_ex)
{
MessageBox.Show(i_ex.Message);
}
//StartService("RDPBFP_Service");
}
So it works fine at first time running it, but second time running it crashes at File.WriteAllBytes.
The service is not running, Windows clearly tells me it's used by my Installer Application when trying to delete it from Windows Explorer.
I'd really appreciate an beginner(which i am) friendly explanation why this happens the way i do it and in best case a solution. I found this post but this did not worked for me.
Thanks in advice.
PS: I know there are Setup Projects and more convenient/professional things, but thats not what i need/want
Well i am now installing it via cmd Process and sc create, still wonder why the InstallHelper wont release the file after installed successfully
i have created C# WinForm on my Windows server 2008 and it works fine.
but when i transfert this MyProg.exe into computer window 7, and i run it, nothing happen.
my code:
[STAThread]
static void Main()
{
try
{
Application.SetCompatibleTextRenderingDefault(false);
DevExpress.UserSkins.BonusSkins.Register();
Application.EnableVisualStyles();
//Pour TEST
//Le_ClientID = "850001";
//Le_Login = "850001FA";
using (var loginForm = new Login())
{
if (loginForm.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
}
Application.Run(new Le_MainForm());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Anybody have an idea ?
event log show:
- System
Provider
[ Name] Application Error
EventID 1000
[ Qualifiers] 0
Level 2
Task 100
Keywords 0x80000000000000
TimeCreated
[ SystemTime] 2012-05-14T09:40:39.000000000Z
EventRecordID 3557
Channel Application
Computer anjouachemineme
Security
EventData
FrontEnd_Offline.exe
1.0.0.0
4fb0c28b
KERNELBASE.dll
6.1.7601.17651
4e2111c0
e0434352
0000d36f
f84
01cd31b59ee78b7d
C:\Soft8_Local\FrontEnd_Offline.exe
C:\Windows\system32\KERNELBASE.dll
dcb7cb01-9da8-11e1-bf8c-1c6f65c1ad74
Thanks you in advance,
Stev
PS: As i lunch MyProg.exe, it listed on Task Manger, but it disapear (killed) in about 3 second after.
Execute the exe (Start as Administrator)
or
this may happen if you dont have Framework Installed in which you created the application by default windows 7 comes with 2.0 and 3.5 Framework . if you created application in visual studio 2010 then you need to download FrameWork 4.0 from Microsoft website to run that exe in Windows 7
you can download Framework 4.0 from here
I just encountered this issue in a Windows form App I created. Apparently there is a plethora of issues that can cause this. In my case you could open the Task Manager, click the application, see it open in the task manager, and immediately close. The only way to see what the issue was, was to look at the event viewer and find the error.
The first is dependencies. Like mentioned above, ensure all required .dlls are included and that you have the required framework(s) installed.
Second KERNELBASE.dll can become corrupted. To ensure that is not the case you can run the System File checker. Instructions can be found here: http://support.microsoft.com/kb/929833
Third, is my case. I had a method running in the constructor of Program.cs which is the first thing instantiated when you start a windows form app. I had a bug in code that was causing an exception before any exception handling was created. To fix the problem I moved the code to a point after I create an unhandled exception method as such:
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
in my forms constructor. Now the program would start and actually throw an error. I then just had to fix the bug in my code.
I hope this can help you or anyone else out there.
I am trying to follow this walkthrough.
I'm using Visual Studio 2010 Premium.
The only events I see in Server Explorer or in Event Viewer are "Service started successfully." and "Service stopped successfully."
Here is the service code:
namespace MyNewService
{
public partial class MyNewService : ServiceBase
{
public MyNewService()
{
InitializeComponent();
if (!EventLog.SourceExists("MySource"))
{
EventLog.CreateEventSource("MySource", "MyNewLog");
}
eventLog1.Source = "MySource";
eventLog1.Log = "MyNewLog";
}
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart");
}
protected override void OnStop()
{
eventLog1.WriteEntry("In onStop.");
}
}
}
I had the same issue with Visual Studio 2010 Professional on Win 7 64. My newly compiled service was installed with InstallUtil.exe running as Administrator. It started and stopped correctly. No exceptions but no amount of refreshing the Event Viewer revealed a new event log. Fran71's suggestion worked for me: I closed the Event Viewer and reopened. VoilĂ , the newly created application log file appeared.
FWIW, I ran into this problem in Win8 and found that Refreshing the Event Viewer did not cause my newly created Event Log to show up, but closing and reopening Event Viewer did. Was driving me insane since no exceptions were being thrown when Creating the Event source or writing a log entry.
Probably a permissions problem. Like the commenter said, try running VStudio or your compiled service as an Administrator.
Also, you can still debug a service - put a thread.Sleep(up to 20 seconds) as your first line (to give yourself time to attach the debugger), then put a break point on the line after that. Then go Tools --> Attach To Process and select your .exe. If you get that done before the end of your Thread.Sleep() then you should break.
Keep in mind that the service must complete the OnStart within IIRC 30 seconds or Windows will think it is not responding and kill your process, so move your code out of the service start if you are going to do much debugging. Just throw a timer in there or something.
To make it easier to debug, consider moving your functionality to a DLL and then keep your service to just enough code to call into your DLL - this will ease unit testing and debugging - but don't forget that lots of things change when you're actually running it as a service.
I'm not using a Windows Form Timer--I'm using a System.Threading.Timer. No exceptions are raised when instantiating the timer, and to my understanding, System.Threading.Timer's do not need to be explicitly started.
I've tried using a System.Timers.Timer (See comments in code) and changing the signature of the callback with no luck. Inside the callback method, I stubbed in some EventLog writes, and not even the first writes to the event log. All I see in the Event Log is MyService.OnStart fired followed by MyService started (these are both from the OnStart event). Why aren't the timer callback events firing?
public partial class MyService : ServiceBase
{
private static System.Threading.Timer timer;
public MyService()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("MyService"))
{
System.Diagnostics.EventLog.CreateEventSource(
"MyService", "MyServiceLog");
}
eventLog1.Source = "MyService";
eventLog1.Log = "MyServiceLog";
}
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("MyService.OnStart event fired");
// setup timer to poll and execute an event
//Timer timer = new Timer(new TimerCallback(CheckCalls), null, 0, 10000);
try
{
timer = new System.Threading.Timer(new System.Threading.TimerCallback(CheckCalls), null, 0, 10000);
}
catch (Exception ex)
{
eventLog1.WriteEntry(ex.Message + " Stacktrace: " + ex.StackTrace);
}
eventLog1.WriteEntry("MyServicestarted");
GC.KeepAlive(timer);
}
}
and the callback method, CheckCalls:
private static void CheckCalls(object objectState)
{
EventLog eventLog1 = new EventLog("MyServiceLog", "DAVIDWIN7", "MyService");
eventLog1.WriteEntry("MyService is polling");
}
Arg--For some reason when you Build->Clean Solution, then Build->Build Solution, Visual Studio does not rebuild your setup project. I believe my code above works fine, but I had tried many different fixes without explicitly right-clicking the setup project and selecting Build.
I thought Clean Solution would force all projects to be rebuilt on next build???
it's got to be an error with the timer thread writing to the event log.
I got it working on my computer but I replaced all the eventlog with Console.writeline because I didn't want to mess with my event log permissions.
Did you check if the account under which the service is running has access to the eventlog?
Please can you go and download this test application which mirrors exactly the scenario you are talking about:
https://docs.google.com/leaf?id=0Bw_NnV9fhgmgMThjNDgzOTgtODNiOC00NDE1LWEyMTYtNzVhOTMyNzlmZjZk&hl=en&authkey=CMuupNkC
I've just created this. It's a service that effectively uses the same code as you. The only difference is that I have used the toolbox to drag and drop an eventlog on to the service designer - setting the log to 'Application' and the source to 'Service1'.
Open a VS command prompt at the project folder, go to bin\debug and run installutil windowsservice1.exe - specifying some credentials (so you're installing the dev service directly from your bin output folder).
Start the service and monitor the application log - it will write every ten seconds as you expect to see from your code.
Assuming this works on your machine(tm) like it does on my machine(tm) then I would suggest that the problem is the event logging itself, or, horror of horrors - your service isn't running from your build output folder (most of the devs in my team insist on running their dev services from a different folder and then swear when they forget to actually update the binaries when they start debugging it!).
As I suggested in my comment, you really need to be able to attach the debugger to this and breakpoint the callback to verify that it's not getting fired. I never rely on the eventlog for diagnostics messages simply because the log might be full, or permissions might prevent you etc etc - it might be a windows platform component, but it's not as reliable as I would like.
The debugger, however, rarely lies (unless the deployed binaries are out of date ;) ). Compile a debug build of your project and make sure it's the one that is installed in the services list, start it up and then attach directly to the service exe (there's no point trying to attach to [service].vshost.exe - VS cannot auto-attach or host windows services as the only way they can run is via svchost.exe shelling them).
Hope this helps.