I coded a C# screensaver which works in preview (install) mode, config or even test mode. However, when reaching the windows timer to launch it, screen goes black, I see the mouse loading icon for 2-3 sec and then the screen revert on the desktop.
I add a log file entry as the first line of code in my main()
and it seems like this code is never run when launched by windows.
Using Visual studio 2017 on Windows 10.
Since I am using an old 3D engine, I made sure to have the app.config modified:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
<supportedRuntime version="v1.1.4322"/>
</startup>
</configuration>
I renamed Screensaver.exe to Screensaver.scr along with the app.config to Screensaver.scr.config. Copied these with my engine dll in SysWOW64 folder.
Build plateform target = x86.
I tried both debug and release build... And I used the same code structure to do a simple example of a screensaver displaying text and it worked therefore I really think the issue comes from the usage of the 3D engine dll.
Would you guys have any advice? Is there some specificities in the config that applies to a .scr? Can't find any lead anywhere and I am out of idea....
Here is the main code if it can help:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using TV3D;
namespace ScreenSaver
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
LogMessageToFile("Hello, World");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
CLTV3D tv3d = new CLTV3D();
if (args.Length > 0)
{
string firstArgument = args[0].ToLower().Trim();
string secondArgument = null;
// Handle cases where arguments are separated by colon.
// Examples: /c:1234567 or /P:1234567
if (firstArgument.Length > 2)
{
secondArgument = firstArgument.Substring(3).Trim();
firstArgument = firstArgument.Substring(0, 2);
}
else if (args.Length > 1)
secondArgument = args[1];
if (firstArgument == "/c") // Configuration mode
{
Application.Run(new ScreenSaverSettingsForm());
}
else if (firstArgument == "/p") // Preview mode
{
if (secondArgument == null)
{
MessageBox.Show("Sorry, but the expected window handle was not provided.",
"ScreenSaver", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
IntPtr previewWndHandle = new IntPtr(long.Parse(secondArgument));
Application.Run(new TVForm(previewWndHandle, tv3d));
}
else if (firstArgument == "/s") // Full-screen mode
{
tv3d.TV.AddToLog("full screen mode argument detected");
foreach (Screen screen in Screen.AllScreens)
{
TVForm tv = new TVForm(screen.Bounds, screen.DeviceName, tv3d);
tv.Show();
}
Application.Run();
}
else // Undefined argument
{
MessageBox.Show("Sorry, but the command line argument \"" + firstArgument +
"\" is not valid.", "ScreenSaver",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
else // No arguments - treat like /c
{
Application.Run(new ScreenSaverSettingsForm());
}
}
static public string GetTempPath()
{
string path = System.Environment.GetEnvironmentVariable("TEMP");
if (!path.EndsWith("\\")) path += "\\";
return path;
}
static public void LogMessageToFile(string msg)
{
System.IO.StreamWriter sw = System.IO.File.AppendText(
GetTempPath() + "My Log File.txt");
try
{
string logLine = System.String.Format(
"{0:G}: {1}.", System.DateTime.Now, msg);
sw.WriteLine(logLine);
}
finally
{
sw.Close();
}
}
}
}
Looks like you've narrowed it down to the 3d component.
Without the log file you can be sure the application fails to start, and without an error message it's hard to diagnose why. Here are some troubleshooting steps.
Try:
Assembly.Load
in a Try/Catch,If the above doesn't work setup DebugDiag (or AdPlus with WinDbg and SOS) and analyze a crash dump.
Failing that, .Net 1.1 is like 15yrs old!!! Do yourself a favor, it will be so much easier to use an up to date library.