how to run wamp server in c# - c#

How do I do this? Can this be done through code in C# ? I use this code to do this but it doesn't work .
using System;
using System.Diagnostics;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Process.Start(#"C:\wamp64\wampmanager.exe");
}
}
}

Related

Error CS0116: A namespace cannot directly contain members such as fields or methods

Ok so im trying to make a program that checks if a program is currently running. It is giving me a error when ever i declare a void. I am new to C# so im sorry if its a stupid.
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.VisualBasic.ApplicationServices;
namespace IsProgramRunning
{
private void IsRunning()
{
Process[] pname = Process.GetProcessesByName("VLC Player");
if (pname.Length > 0)
{
MessageBox.Show("Process Running");
}
else
{
MessageBox.Show("Process Not running");
}
System.Threading.Thread.Sleep(5 * 1000);
}
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
}
If im going about this all wrong and there is a easy way to do it in c++ that would be good to
To have instance members and methods, you need a class. You have confused a namespace with a class
namespace MyAwesomeNameSpace
{
public class ProgramRunningHelper
{
// put your class code here
}
}
Compiler Error CS0116
A namespace cannot directly contain members such as fields or methods.
A namespace can contain other namespaces, structs, and classes.

WCF with Duplex Communication

Whenever I am using Window Forms It works Fine But it always give error with console applicion.
Error- The socket connection was aborted. This could be caused by an
error processing your message or a receive timeout being exceeded by
the remote host, or an underlying network resource issue. Local socket
timeout was '00:01:00'.
Here is My Code
Contract
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace ClassLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IReportService" in both code and config file together.
[ServiceContract(CallbackContract=typeof(IReportServiceCallbak))]
public interface IReportService
{
[OperationContract(IsOneWay=true)]
void ProcessReport();
}
public interface IReportServiceCallbak
{
[OperationContract(IsOneWay=true)]
void Progress(int percentage);
}
}
Service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading;
namespace ClassLibrary1
{
public class ReportService : IReportService
{
public void ProcessReport()
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(50);
OperationContext.Current.GetCallbackChannel<IReportServiceCallbak>().Progress(i);
}
}
}
}
Client
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Threading.Tasks;
using System.Threading;
namespace DuplexClientsss
{
class Program
{
static void Main(string[] args)
{
new Tests();
} }
class Tests : ReportService.IReportServiceCallback
{
ReportService.ReportServiceClient obj;
public Tests()
{
obj = new ReportService.ReportServiceClient(new InstanceContext(this));
obj.ProcessReport();
}
public void Progress(int percentage)
{
Console.WriteLine(percentage);
}
}
}
new Task
(
()=>
{
obj.ProcessReport();
}
).Start();

Task.Factory.StartNew() not working for me

I wrote this small application. for some reason i am not being able to print "Hello from a thread" when i run this program. however if i debug it and put a breakpoint inside Do() method, it does print.
Any ideas?
using System;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
internal class Program
{
private static void Main(string[] args)
{
Task.Factory.StartNew(Do);
}
private static void Do()
{
Console.WriteLine("Hello from a thread");
}
}
}
Are you sure that the program simply isn't closing before you can see the output? Because this works fine for me.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
private static void Main(string[] args)
{
Task.Factory.StartNew(Do);
Console.Read();
}
private static void Do()
{
Console.WriteLine("Hello from a thread");
}
}
}
Edit: Added the comment I wrote in response to this, including my reasoning to why the text wasn't printed.
Its either because the application closes down before the thread has the possibility of outputting the string to the screen. It's also possible that you simply cant see it because it closes straight away. Either way the reason it worked with the breakpoint is because you keep the application alive longer.
Try this.
using System;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
internal class Program
{
static void Main(string[] args)
{
Task.Factory.StartNew(Do);
Console.ReadKey();
}
static void Do()
{
Console.WriteLine("Hello from a thread");
}
}
}

SafeArrayTypeMismatchException using VirtualBox from c#

I'm using the VirtualBox type library from C# as follows:
using System;
using System.Collections.Generic;
using System.Text;
using VirtualBox;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
IVirtualBox vbox = new VirtualBoxClass();
IHost h = vbox.Host;
Array a = h.USBDevices;
}
}
}
The line Array a = h.USBDevices; causes a SafeArrayTypeMismatchException. Has anyone else had the same problem?
Thanks!
var a = (IUSBDevice[])h.USBDevices

How to write an app-launching application with arguments in C#?

How to if I want to write an application that launches Firefox with arguments ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Launcher
{
public static class Program
{
public static void Main(string[] args)
{
Process.Start("C:/Program Files/Mozilla Firefox/firefox.exe");//this is ok
Process.Start("C:/Program Files/Mozilla Firefox/firefox.exe -P MyProfile -no-remote");// this doesn't work
}
}
}
You will need to specify the process.StartInfo.Arguments
See this question: Calling an application from ASP.NET MVC
You will need to use the process.StartInfo.Arguments, as shown here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Launcher
{
public static class Program
{
public static void Main(string[] args)
{
Process firefox = new Process();
firefox.StartInfo.FileName = #"C:\Program Files\Mozilla Firefox\firefox.exe";
firefox.StartInfo.Arguments = "-P MyProfile -no-remote";
firefox.Start();
}
}
}

Categories

Resources