|
Debugging is generally the best way to detect 'Object reference not set' errors.
Once you find where the error occurs, you can check why that particular item is null.
The problem / solution may not necessarily in this line but rather somewhere else.
|
|
|
|
|
My JavaScript sends a selected path, for example C:\files to com ActiveX, I catch it on C# like this:
[ComVisible(true)]
public string MyParam
{
get
{
return myParam;
}
set
{
myParam = value;
}
}
I then launch a program like this:
[ComVisible(true)]
public void LaunchPlayer()
{
Process.Start("wmplayer.exe", "ANYFOLDER");
}
The problem is that how do I launch the program so that it uses the current value on myparam on "ANYFOLDER"?
|
|
|
|
|
How about:
Process.Start("wmplayer.exe", MyParam);
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Damn, I tried that but I'll retry. This might have been an embarrassing question 
|
|
|
|
|
Be careful of the little trap with long path names. If the pathname contains spaces then the entire string must be surrounded with double quotes, like:
string MyParam = "C:\\Users\\Joni_78\\My Backup Files";
Process.Start("wmplayer.exe", "\"" + MyParam + "\"");
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thank you that worked . One thing, I get the MyParam on JavaScript from Windows Media Center (window.external.MediaCenter.MediaContext.GetProperty("Name")), it is in form dvd:///G:/ANYFOLDER/ I know how to get rid of the dvd:/// in Js but how to do it in C# and even better if possible, is it possible to do it here?
string MyParam = "C:\\Users\\Joni_78\\My Backup Files";
Process.Start("wmplayer.exe", "\"" + MyParam + "\"");
|
|
|
|
|
This is just string manipulation. What you would do in C# is very much the same as in Javascript. You could do it when you save the string in your MyParam setter, or when you return it from the getter. Look at the String [^] class for details.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thank you 
|
|
|
|
|
Need to do the following:
given a array 'a' of double of monotone increasing values and a given value I have to find the index in the array so that V<a[i] &&="" v<="a[i+1]," if="" v="a.Min()," then="" return="" 0,=""> a.Max() or V < a.Min() the return 100.
double[] a = new double[]{1,2,3,4}
I look for a function F so that for example (implementing whaat described above:
F[0.5] =100;
F[1] = 0;
F[2] = 0;
F[2.1] =1;
F[4] =3;
F[4.1] =100;
It can be done with for...loop of course. Is it efficent or it is better using LINQ or Array.FindIndex or...smarter solution? (if it is more efficent LINQ or Array.FindIndex, how to do it?)
|
|
|
|
|
TheGermoz wrote: is better using LINQ
No. Probably not anyway, but I'm unclear what you are trying to do.
|
|
|
|
|
100 is a stupid failure value. What if you have a 100 element array? -1 is traditional for 'not found' (see Array.IndexOf and the like).
I think your expected output is wrong ... if F[4] is 3 then F[2] must be 1.
Does
int F(double[] arr, int value){
return -1 + Array.FindIndex(arr, d => d >= value);
}
... do what you want?
|
|
|
|
|
yes sorry my error F[2] must be 1.
Yes is solve it. The only error is for F[1] should be 0 and not -1.
Is it more efficient Linq or BinarySearch?
modified 27-Nov-12 7:47am.
|
|
|
|
|
If the values are monotonically increasing, Array.BinarySearch[^] will probably be the most efficient way to find a particular value.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I would put it in a List . That contains a functions to search.
See here[^].
List<double> a = new List<double>();
a.Add(1);
a.Add(2);
a.Add(3);
a.Add(4);
Hope this helps.
|
|
|
|
|
TheGermoz wrote: It can be done with for...loop of course. Is it efficent or it is better using LINQ or Array.FindIndex or...smarter solution? (if it is more efficent LINQ or Array.FindIndex, how to do it?)
The difference in performance would only just be better for LINQ.
If your function is not many to one, you could directly use a key value pair collection.
|
|
|
|
|
Hello! Can you get advise me how send data from PHP script to local program developed on C#?
|
|
|
|
|
Junoli wrote: Hello! Can you get advise me how send data from PHP script to local program developed on C#?
Sure. "research a lot".
You can launch an external app from PHP using the exec[^] method. It doesn't matter what language the app was written in.
|
|
|
|
|
Maybe i expressed mind not good. I have php script on WebServer what must send data to my local machine to localhost (client WTF C#). How i understood correctly - function exec runs process on server.
|
|
|
|
|
I know there is possible to work with sockets.
In the PHP i can open socket and send it data. And in C# connect to socket and read sent data.
|
|
|
|
|
Yup, that's an option; It's easier if the C# app can initiate the communication, since that'd mean you'd only have to GET/POST a webpage.
Communicating over a socket should be possible, but I'd seriously spend some time looking for an easier way.
|
|
|
|
|
Profitability to do that client (C#) not make request on Server(PHP) every time and do it contra.
That is mean the server will send data if it need, once.
How send data to socket in PHP i know, but how it take on C# WTF - don't know. Can you line me on true way, i am beginner
|
|
|
|
|
A webserver typically serves data, it doesn't push it to the client.
Junoli wrote: That is mean the server will send data if it need, once.
My last article is about polling a webserver, and it isn't continually reading data; it's asking the webserver whether or nor a specific file has changed. If it has, it's downloaded and processed.
If you need a "push"-mechanism that actively works with it's clients, I'd suggest a server-application in C#, not a PHP-website.
|
|
|
|
|
Okay, give me please source example C# server app, and how it set to server?! Thank you
|
|
|
|
|
Junoli wrote: Okay, give me please source example C# server app
Voila[^].
|
|
|
|
|
Thank you. So how i can start this server program on the WebServer?
|
|
|
|