i have a multi environment program that runs on windows ce machines, regular pc and windows mobile.
I am using a database and files.
because of the windows CE i need to use the Directory.GetCurrentDirectory() func before the file use and then reset the current directory (using the Directory.SetCurrentDirectory() func) back to the old one because it changes once i do the I\O in order to continue using the DB.
because the windows mobile does not support this functions there is an exception thrown during runtime a "NotSupporetedException".
any functions that i could use instead of this that should fix my problem?
or any way i can check during runtime what environment the application is running on and not use this functions if the application runs on mobile?
please help,
thanks in advance.
I don't fully understand your directory problem, but you can certainly check which platform you're on at runtime:
if (Environment.OSVersion.Platform == PlatformID.WinCE)
{
...
}
else
{
...
}
Related
I want to create an app that calls the Hololens default browser. I used the following code, but whenever I call this function, the Application will crash. If this code is not suitable for UWP, how can I call HoloLens' default browser in an app?
The version of the software I am using is:
1.Unity 2018 3.11f
2.Mixed Reality Toolkit v2.0.0 RC1
3.Visual Studio 2017
public void OpenAnlagenWiKi_URL()
{
string tempUrl = string.Format("{0}", AnlagenWiKi_Link.text);
Application.OpenURL(tempUrl);
}
I hope to successfully call HoloLens' default browser in the app.
It's a bit tricky. Any Hololens application is actually UWP process.
First of all, you need to switch it into the background mode by calling AppResourceGroupInfo.StartSuspendAsync. The details are here.
When the app would go into background, you should call open process
System.Diagnostics.Process.Start("http://google.com");
I am using compact framework 3.5 to build a windows mobile application.I need to restart the application after saving the application settings. I tried the below one,from How do I restart my C# WinForm Application?
string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
Process.Start(path, "");
I am not getting any error,but my application is not restarting.I am checking in my simulator.Do restart working in mobile simulator.
Need solution to solve this problem.
Thanks
Try using this code to access the path:
string path;
path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
But to restart the application you can use RunAppAtTime method:
var time = DateTime.Now.AddSeconds(3); // immediate restart
Notify.RunAppAtTime(thisName, time); // restart the app
Note that although the time is set to 3 seconds from now it will restart immediately. To have a real delay the time difference must be higher than 10 seconds.
More on that here: https://stackoverflow.com/a/6133136/3330348
An .net application can not restart itself. As it is running on Mobile only one instance is ensured by the framework, if you had targetted Windows CE, you would be able to run multiple instances.
So, RunAppAtTime is a good solution to let the app be started by the Mobile scheduler after the app itself has terminated using Application.Exit().
Another option would be a second application that is started at Application.Exit(), watches the process list to see when main applicaton is terminated (or use GetProcessExitCode), and then starts a new instance of main application. This techique is used for updaters etc.
I actually need an expert advice in resolving a situation regard calling InitPK.dll (C++ dll) as a service in windows 7 (Code attached). The dll is loaded successfully but PKAgentInit method is returning 0(false) on Windows 7 using windows service the same works okay in windows XP also the code works fine when exec as a console program on windows 7 .
Could you please guide us why PKAgentInit method is returning 0 on Windows 7 and what is the recommended way of calling Agent under Windows 7 using windows service.**
Code:
typedef UINT (CALLBACK* INITPK)();
m_LogDebug->Log(2,nThreadId,cMethod,
"Pre-requisite applications are running so executing Agent...");
hDll = LoadLibrary(AgentPath.c_str());
if(hDll == NULL)
{
m_LogDebug->Log(0,nThreadId,cMethod,
"Failed to load [%s]",AgentPath.c_str());
return false;
}
INITPK InitPK_Func;
if((InitPK_Func = (INITPK)GetProcAddress(HMODULE(hDll), "PKAgentInit")) == NULL)
{
m_LogDebug->Log(0,nThreadId,cMethod,
"Failed to load proc address [%s]",AgentPath.c_str());
return false;
}
UINT Res = InitPK_Func();
// returning 0 which means Agent is not executed successfully.
// Ideally it should return 1.
m_LogDebug->Log(0,nThreadId,cMethod,"PKAgentInit returned [%d]",Res);
Without seeing the source to InitPK_Func() it's hard to say but I'd guess that it's a privileges problem and the service isn't running as a user that can do what you need to do. Perhaps the code in question needs to be elevated (might be why it works on XP), or perhaps it's touching a network resource (might be why it works as a console app on Win7).
But really, you need to debug the problem function and maybe change it to return a little more information about why it failed.
I have written a few C# apps that I have running via windows task scheduler. They are running successfully (as I can see from the log files that they are writing ) but windows task scheduler shows them returning a last run result of 0xE0434352. Is there something I need to do in my C# application so that it returns a success code to the windows task scheduler?
Another option is to simply use the Application log accessible via the Windows Event Viewer. The .Net error will be recorded to the Application log.
You can see these events here:
Event Viewer (Local) > Windows Logs > Application
When setup a job in new windows you have two fields "program/script" and "Start in(Optional)". Put program name in first and program location in second.
If you will not do that and your program start not in directory with exe, it will not find files that are located in it.
Hans Passant was correct, I added a handler for AppDomain.CurrentDomain.UnhandledException as described here http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception(v=vs.71).aspx I was able to find the exception that was occurring and corrected it.
I was referencing a mapped drive and I found that the mapped drives are not always available to the user account that is running the scheduled task so I used \\IPADDRESS instead of MAPDRIVELETTER: and I am up and running.
In case it helps others, I got this error when the service the task was running at didn't have write permission to the executable location. It was attempting to write a log file there.
I had this issue and it was due to the .Net framework version. I had upgraded the build to framework 4.0 but this seemed to affect some comms dlls the application was using. I rolled back to framework 3.5 and it worked fine.
I got the same error but I have fixed it by changing the file reading path from "ConfigFile.xml" to AppDomain.CurrentDomain.BaseDirectory.ToString() + "ConfigFile.xml"
In my case, this error due to file path error because task manager starts program from "System32" as initial path but the folder we thought.
I was getting the same message message within dotNet Core 2.2 using MVC 5, however nothing was being logged to the Windows Event Viewer.
I found that I had changed the Project sdk from Microsoft.NET.Sdk.Web to Microsoft.NET.Sdk.Razor (seen within the projects.csproj file). I changed this back and it worked fine :)
In my case it was because I had message boxes. Once I commented that code out, it started working. I remembered that could be a problem when I looked at the event log as suggested in this thread. Thank you everyone!
I encountered this problem when working with COM objects. Under certain circumstances (my fault), I destroyed an external .EXE process, in a parallel thread, a variable tried to access the com interface app.method and a COM-level crash occurred. Task Scheduler noticed this and shut down the app. But if you run the app in the console and don't handle the exception, the app will continue to work ...
Please note that if you use unmanaged code or external objects (AD, Socket, COM ...), you need to monitor them!
Also message box in PowerShell. I converted PowerShell script to exe. When running as admin it's worked but in task schedule I received this error also.
There was an line in PowerShell script with write-output. After commented this line and compile new exe Task Schedule was completed successfully.
It is permission issue in my case the task scheduler has a user which doesn't have permission on the server in which the database is present.
i need to transfer Text.txt file from PC (using WebService)
to Windows-mobile 5.0 - and from Windows-mobile to PC
can i get any sample code in C# for the WebService and the Windows-mobile ?
thanks in advance
You cannot directly transfer files. you should try ActiveSync RAPI to send information.
Use OpenNETCF. It's a useful compact framework for WindowsMobile (.NET).
Try this:
string fileToSendToDevice = #"C:\Text.txt";
OpenNETCF.Desktop.Communication.RAPI rApi = new OpenNETCF.Desktop.Communication.RAPI();
if (!rApi.DevicePresent) return; // no active sync
if (!rApi.Connected) rApi.Connect();
if (!File.Exists(fileToSendToDevice)) return; // file not found
rApi.CopyFileToDevice(fileToSendToDevice,
Path.Combine(#"\My Documents\", Path.GetFileName(fileToSendToDevice)));
The concept is really no different than PC-to-PC if you intend to use a Web Service for the transfer (assuming the Web Service is running on the PC). Find any example on the web that transfers a file to and from a Web Service and it will likely be applicable.
If you then have a question that is more specific to WinMo/CF or an implementation problem, feel free to update this question about what you've tried and what about it is not working.
One of these two examples will probably help. The code for the PC will be likely the same if not simpler.
Then you just need to write the web service.