WPF Application crashes on WIndows 7 when command executable.Start() is run - windows

I've got a tiny Portal I´m writing, and this portal is supposed to launch installers on button click. I´m developing on VS2010 on a WinXP SP3 station, and on this machine, even fter compilation and publishing, everything works as expected. However, when i run the compiled application in Windows 7, it crashes...The application work, it just crashes when i click a button for program installation.
The programming looks like this:
private void button_access_Click(object sender, RoutedEventArgs e)
{
Process executable = new Process();
string executablePath = "D:\\Visual Studio 2010\\SAFE_Portal1\\SAFE_Portal1\\Extra Programs\\AccessRT2003.exe";
executable.StartInfo.FileName = executablePath;
executable.Start();
}
It specifically crashes on thr button_access_Click procedure...
Any ideas as to why this could be? I`ve tried looking around here in Stackoverflow, and in other forums, but to no avail...
Any help or direction is ganz welcome!

Try this:
try
{
Process executable = new Process();
string executablePath = "D:\\Visual Studio 2010\\SAFE_Portal1\\SAFE_Portal1\\Extra Programs\\AccessRT2003.exe";
executable.StartInfo.FileName = executablePath;
executable.Start();
}
catch (Exception msg)
{
MessageBox.Show(msg.Message);
}
What message are you getting?
Are you sure you want to use fixed paths in your application? If so you should at least check if the file you try to start exists beforehand. Otherwise an exception will be thrown which could be the problem here.
if (File.Exists(executablePath))
{
...
}

Related

conhost.exe process duplication in Visual Studio | can't close conhost

I have a windows forms project and it several forms each one had a button to close the one form and open another by doing that code:
private void button3_Click(object sender, EventArgs e)
{
Menu MenuForm = new Menu();
MenuForm.Show(); // Shows main menu
this.Hide();
}
When I switched between forms it duplicated consoles on the background and i can't close it.
I tried debug=>stop debugging and manually killing process in task manager.
enter image description here
all consoles consume such memory in my pc, they seem to automatically run as i open VS

Xamarin Android debugging: No compatible code running

Context
I am using VS 2017.3 to develop Xamarin.Forms application. I am trying to diagnose where and why an Exception occur on my code.
I can successfully deploy run and debug my application using the SDK Android Emulator (HAX x86).
However in case an Exception occur I can not see any information about the Exception, see attached picture, settings.
Question
Is this normal in Android debugging, or missing I something?
...and my build settings:
I wanted to expand on #Uraitz's answer because it helped me figure out the problem.
First, as he explains, you will want to add an event handler in your activity, as shown in the following code:
protected override void OnCreate(Bundle savedInstanceState)
{
...
//subscribe to unhandled event
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
...
}
private void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
In my case I put a breakpoint inside CurrentDomainUnhandledException so I could inspect the exception.
However, even with that breakpoint in there, I ran my code and still got a confusing no-callstack error.
At this point I thought the solution wasn't working. In fact it is, but I had to click the Play (continue) button multiple times before my app would hit the breakpoint:
After clicking that button two times, I finally hit the breakpoint:
If you want to get the callstack in the debugger, you will have to dive in a few levels before it is available, but you can do so by looking at the event args parameter.
The moral of the story is - if you have added the event handler but you still aren't hitting the breakpoint (or seeing output) - keep clicking the Continue button!
Just continue, then look through the Output, it will show you the stack trace of the exception. It is a good idea to learn how to read through the log files to find information about exceptions.
You can subscribe on each platform main constructor to UnhandledException event this will give you more information about exception before break debug.
for example in Android:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
//subscribe to unhandled event
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}
If you need each platform explanation ask for them :)
Deleting the bin and obj folders solved it in my case.
I got similar issue, after investigating, I just have to disable the Xamarin Inspector.
Ill just throw this in the mix.
I was getting a "No compatible code running" error when attempting to break on otherwise 'working' code.
After struggling with this I decided to go back to an older version of visual studio where it didn't happening.
This gave me the idea to reset my Exception settings, and then the issue went away.
Seemingly there are a number of handled exceptions that any given library might be throwing, and if you choose to break on a particular condition you may well see this.

JavaFX Native Bundle Splash Screen

I'm using the javafx-maven-plugin and IntelliJ IDEA on Windows 7.
I'm trying to get a splash screen to show while my JavaFX application boots up, like this:
I tried using the SplashScreen-Image manifest entry—and that works, but only if you click on the .jar—I'm deploying the application as a Native Bundle and so the user clicks an .exe (or a shortcut to an .exe) not the actual .jar.
When you click the .exe no splash screen is shown.
This SSCCE I made will help you help me.
If I'm deploying my app using the javafx-maven-plugin, (which, if I'm not mistaken, uses the JavaFX Packager Tool, which uses Inno Setup), how can I get a splash screen to show after the user clicks the .exe?
More Findings:
Looking at the installation directory, I find a .dll called runtime\bin\splashscreen.dll. Does that mean it can be done?
The native launcher does not respect that spash-screen, it is only when being invoked by the java-executable. As the native launcher is loading the JVM internally, this won't work.
I haven't found a proper way to get this working, not even with some preloaders. Maybe you can find this helpful: https://gist.github.com/FibreFoX/294012b16fa10519674b (please ignore the deltaspike-related stuff)
Copied code:
#Override
public void start(Stage primaryStage) throws Exception {
// due to the nature of preloader being ignored within native-package, show it here
SplashScreen splashScreen = new SplashScreen();
splashScreen.show(new Stage(StageStyle.TRANSPARENT));
// needed for callback
final SomeJavaFXClassWithCDI launcherThread = this;
// for splashscreen to be shown, its needed to delay everything else as parallel task/thread (it would block otherwise)
Task cdiTask = new Task<Void>() {
#Override
protected Void call() throws Exception {
// boot CDI after javaFX-splash (this will "halt" the application due to the work done by CDI-provider
bootCDI(launcherThread);
// push javaFX-work to javaFX-thread
Platform.runLater(() -> {
primaryStage.setTitle("Some Title");
// TODO prepare your stage here !
// smooth fade-out of slashscreen
splashScreen.fadeOut((ActionEvent event) -> {
primaryStage.show();
splashScreen.hide();
});
});
return null;
}
};
// run task
new Thread(cdiTask).start();
}
In short: I'm creating my splashscreen myself.
Disclaimer: I'm the maintainer of the javafx-maven-plugin

How can I launch an application through Microsoft Visual Studio?

I am still new to using Visual Studio, any windows programming really, and I am trying to make an application Launcher for Microsoft Office applications. I have already made the interface but dont know how to make the buttons actually launch the programs. Any help is appreciated.
You can add System.Diagnostics namespace to your project and use its Process.Start function to start an external application and for closing a process you can use Process.Close function, save your started process in a variable and close it when ever you want: like this:
static void Main()
{
// ... Open specified Word file.
OpenMicrosoftWord(#"C:\Users\Sam\Documents\Gears.docx");
}
public Process myProcess;
static void OpenMicrosoftWord(string file)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "WINWORD.EXE";
//If skip this line, you'll have an open MS Word with no specific file loaded
startInfo.Arguments = file;
myProcess = Process.Start(startInfo);
}
static void CloseMicrosoftWord()
{
myProcess.Close();
}
for more information check below links
Process.Start Examples
Using Diagnostics.Process to start an external application
Process.Close Method

Visual Studio ASP.NET crashes after Stop Debug in Chrome

I'm working on a website which can stream audio files to the browser. It's a asp.net application which im developing in Visual Studio 2013. To stream the audio to the client im using partial content response using the range request headers. The code looks like this:
[HttpGet, ActionName("GetFile")]
public HttpResponseMessage GetFile(string fileName)
{
var rootPath = AppDomain.CurrentDomain.BaseDirectory;
var fullPath = Path.Combine(rootPath, "SoundFiles", fileName);
byte[] file = File.ReadAllBytes(fullPath);
var mediaType = MediaTypeHeaderValue.Parse("audio/mpeg");
var memStream = new MemoryStream(file);
if (Request.Headers.Range != null)
{
try
{
var partialResponse = Request.CreateResponse(HttpStatusCode.PartialContent);
partialResponse.Content = new ByteRangeStreamContent(memStream, Request.Headers.Range, mediaType);
return partialResponse;
}
catch (InvalidByteRangeException invalidByteRangeException)
{
return Request.CreateErrorResponse(invalidByteRangeException);
}
}
else
{
var fullResponse = Request.CreateResponse(HttpStatusCode.OK);
fullResponse.Content = new StreamContent(memStream);
fullResponse.Content.Headers.ContentType = mediaType;
return fullResponse;
}
}
Every time a song is played this method is called to get the file from the server and to stream it partially to the client. The whole application is built with signalr.
This worked perfectly for me there is nothing wrong with that code. Until i bought a new pc. I installed my Visual Studio 2013 normally on it including IIS Express 8.0 etc. But something strange happened to this.
If I start debugging with Google Chrome, and then if I do normal things to the website but not playing a song (not calling the method), and then stop debugging it again I have no problems. But if I start it in Chrome and play the song (call the method) and then try to stop debugging, visual studio freezes but there is no information that it is hanging. Its just hanging and I cannot close it. I cant even close it with the task manager. No error is showed. If I try to shut down my pc, then the pc won't shut down until I press the power button a long time. Now the strange thing: If I try the exact same thing but in Internet Explorer, Visual Studio works normally and is not hanging at all. This only happens if I use Chrome for debug and only on the same host as Visual studio is running. If I connect a Chrome on a other Device in my network, it does not have any effect.
I figured out, that I can run the application without debugging. If I do that it works good, but if I play a song and then try to close Visual Studio, it shortly hangs for about 30 seconds and then quits.
I am unable to find out what the problem is.
What I already tried to do:
Reinstall Visual Studio 2013
Try with Visual Studio 2015, same effect
Reinstall Windows 8.1
Reset Import/Export Settings in Visual Studio
Run Visual Studio as Administrator
Move SoundFiles to an other directory
Try with Google Chrome Canary, same effect
And the really strange thing is, that it only happens on Chrome on the same machine, and only on my new pc. The same scenario works perfectly on my surface or on the old laptop.
What I could imagin, for the chrome reason is, that chrome uses range requests and ie does not. It takes the full Response of audio as 200 and chrome takes the range as partial content. This could be the problem, but I'm not sure and I don't know how to solve or workaround this problem.
Have you guys an idea, what could causing this problem?
Ok, I didn't manage to find the problem, but I found the solution. Because it was a new PC, there was little bit of bloatware on it. I've uninstalled the things I don't needed, and then it magically worked. No crashes anymore. I have a ASUS ROG G20AJ. I don't know exactly which of the bloatware was causing the problem, but it was some of them. So if you have a similar problem on a ASUS Machine, try uninstalling some of the not used software.
It wasn't Visual Studio crashing, it was the IIS Service. I really think that this is a really strange behaviour, because the crashes did only happen, if I executed the code snippet above... Anyways, it works now!

Resources