|
Using C#,
How would I refresh the desktop? Say I created a shortcut and it did not show after creation, or if I programmatically changed the desktop path in the Registry and would not appear to change until I logged in again. I want to make these changes appear immediately.
Thanks
Rob
|
|
|
|
|
Just guessing that you are using a windows based OS, the best way i can think of is searching for the correct api call on microsofts website (msdn) then make that call. Your can call the graphics object that draws the desktop and tell it to refresh..but i dont think this would fix the problem. Hope this Helps.
Jesse M.
The Code Project Is Your Friend...
|
|
|
|
|
Thanks,
Yeah, the api calls are weird though because they refresh specific desktop items only like wallpaper, screen, but do not address the path of the virtual folder and items within it. I am sure I will get to the right one.
|
|
|
|
|
Im wondering if one of those calls to the api that refreshes (say the wallpaper) also refresh's other things like links and icons ect.
Jesse M.
The Code Project Is Your Friend...
|
|
|
|
|
I'm working on a program to store my DVD collection, download the cover images, etc. I know programs exist to do this already, but I needed a project to learn C#, so this is it.
I've run into a logic problem when downloading Cast/Crew data from IMDB and storing it. My project uses an XML file to store the collection data, in this format:
<owned>
<movie>
<rating>R</rating>
<id>12345</id>
<title>Movie Title</title>
<year>2003</year>
<length>122</length>
<cast>
<star id="12345">Some Guy</star>
<star id="54321">Some Girl</star>
</cast>
</movie>
</owned>
Right now everything but the <cast>...</cast> information is parsed and stored in a ListView control, which works fine. The problem I'm having is how to store the data so that I can click on a person and see all the movies I have with them in it.
In a language like PHP I'd do an array of arrays with associative key => value pairs, like
Stars = array(
'Star ID' => array(
'Movie ID' => 'Movie Title',
'Movie ID' => 'Movie TItle')
);
And the equivalent in C# seems to be a hashtable, but it won't let me do Hashtable[Key].Add(ID, new Hashtable())
So I guess what I need a multi-dimensional Hashtable? Does anyone get what I'm talking about?
|
|
|
|
|
Why not load the data into a dataset? Once it is in a dataset you can apply filters to limit which rows are displayed. Populate into three tables, one table of movie data, one table of star data and one relational table that ties stars and movies together.
|
|
|
|
|
I like Daniel's suggestion of using a DataSet - there's a lot you could do with it if you chose to use it.
Otherwise, you may want to look at the NameObjectCollectionBase from the System.Collections.Specialized namespace.
|
|
|
|
|
DataSets look good, thanks guys.
|
|
|
|
|
I have a relational Access DB and I am wondering if there is any way to get the schema of the entire database and write it in XML. The second thing I am trying to find out is if it is possible to export the XML schema from this Access DB as an Oracle Script that will build an oracle database with the same relationships as my existing Access DB. Thanks for your help, you guys are lifesavers!
Frank
|
|
|
|
|
look at the Data COmmandBuilder classes, should provide the schema for u, dunno about oracle as u need a phd (and a small atomic powerplant) to work with it.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
For our Beta builds, I need to run a command line program just before building the main assembly. Yet the only pre-build setting I can find runs it for ALL configurations.
(I modified the utilities in question to accept a parameter of $(configuration name). Of course, this means the utilities have to now be build and for all configurations. Who's the idiot who came up with this limitation?)
Joe Woodbury
When all else fails, there's always delusion.
- Conan O'Brien
|
|
|
|
|
|
Good idea. Thanks.
Joe Woodbury
When all else fails, there's always delusion.
- Conan O'Brien
|
|
|
|
|
I would like to know if there is any built in function/library in C# which lets me solve the foll. Statistical problem:
Given the mean and the variance of a normal distribution, I want to get the sample points that are arrived at based on the mean and variance.
(Basically some function similar to the Worksheet function NormInv in MSExcel).
Right now I am doing a very kludgy solution where I create an Excel Worksheet function object just to access the function. This makes my application real slow. Moreover I need this type of evaluation to be done possibly 10,000 times as I am developing some kind of a simulator.
Anybody please help !!!!
|
|
|
|
|
Those methods wouldnt be hard at all to implement in a class or two. In fact thats a good idea for your 1st article here at CodeProject.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
I'm sure I remember there being a C# math library on the web somewhere - probably not free though and I can't remember what it was called or whether it supported stats.
Ah, just did a search and there's one here: http://www.centerspace.net/products.php?page=3[^]
The stats library is released next month.
Kevin
|
|
|
|
|
Now that kevin mentioned it. Do a search for Math.NET and Euler.NET on SOurceforge, both provide stats functions i think.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
I'm not sure exactly what you are after, but this may help?
using System;
namespace NormInvFunc{
public class Normal
{
private static double Density(double x)
{
double y=Math.Pow (2*Math.PI ,-.5)*Math.Exp(-.5*x*x);
return y;
}
public static double StandardNormal(double x)
{
double [] a=new double[5];
a[0]=.31938153;
a[1]=-.356563782;
a[2]=1.781477937;
a[3]=-1.821255978;
a[4]=1.330274429;
double K=.2316419;
double L=Math.Abs(x);
double nx=Density(L);
double q=1/(1+K*L);
double S=0;
for(int j=0;j<5;j++)
{
S+= a[j]*Math.Pow(q,j+1);
}
double SND=1-nx*S;
if(x<0)
{
SND=1-SND;
}
return SND;
}
public static double StandardNormalInv(double R)
{
double Delta=1;
double X=0;
double Y=0;
do
{
Y=X-(StandardNormal(X)-R)/Density(X);
Delta=Math.Abs (Y-X);
X=Y;
}
while (Delta>.000000001);
return Y;
}
}
}
NB will not return quite as many decimal places as excel.
|
|
|
|
|
I am try to use multi-thread. I use "lock" like this:
class MyClass<br />
{<br />
private object status = null; <br />
<br />
<br />
myfun() {<br />
...<br />
lock ( status ) {<br />
status = new object(1);<br />
}<br />
...<br />
}<br />
}
But it gave me an "ArgumentNullException", anyone know why?
Thanks in advance.
|
|
|
|
|
You need an actual object to lock.
yyf wrote:
private object status = null
Change line into
private object status = new object()<br />
<br />
And everything will be happy. But then again I'm not sure why you're trying to create the object inside of the lock. <br />
<br />
Jared <br />
<a>jparsons@jparsons.org</a><br />
<a href="http://www.prism.gatech.edu/~gte477n">www.prism.gatech.edu/~gte477n</a>
|
|
|
|
|
|
|
Thanks for all your response. Sorry, I didn't make myself clear.
Actually I want to change the value of status in the lock block. I need to lock it in case some one else are using it.
so it should be something like that:
class MyClass<br />
{<br />
<br />
private object status = null;<br />
private object status0 = new object(0);<br />
private object status1 = new object(1);<br />
private object status2 = new object(2);<br />
<br />
myfunc()<br />
{<br />
...<br />
lock ( status ) {<br />
status = status1;<br />
}<br />
...<br />
}<br />
<br />
}
It has problem as I mentioned.
Maybe I should change it to:
status = new object(0);<br />
lock ( status )<br />
{<br />
status = status1;<br />
}
Another quick question:
From the help in .Net, it suggests I can use either this or typeof(class). But I don't understand how to use "typeof(class)"; I tried "lock ( this )", it worked. But I wonder how about if I have different variables in one class to protect. If I use "lock (this)", it'll bring up some unnecessary blocks. Right? So what should I do in this case?
Thank you very much.
|
|
|
|
|
yyf wrote:
1: status = new object(0);
2: lock ( status )
3: {
4: status = status1;
5: }
I've added line numbers for clarification
This function will not work as you expect it to. For example assume I have two instances of MyClass m1 and m2. Each are created in a seperate thread. m1 executes lines 1-4 and then there is a thread switch. The problem is now the lock is on the previous object status pointed to and there is virtually no way to retrieve that object. Now m2 comes along and executes line 1 and 2. It is locking a completely new object so even though the thread containing m1 is currently inside the lock, the thread containing m2 will proceed into the code block. Now event though status1 will be set correctly in your case, the code is misleading and incorrect.
The easier way to do this is through a property and a locking object.
<br />
public class MyClass<br />
{<br />
private static object Sync = new object();<br />
public static object _status = null;<br />
<br />
public static object status<br />
{<br />
get <br />
{ <br />
lock ( Sync )<br />
{ <br />
if ( _status == null ) <br />
{ <br />
_status = new object();<br />
}<br />
}<br />
return _status;<br />
}<br />
}<br />
<br />
}<br />
Or you can just use a static constructor.
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
Thanks Jared, your answer are great.
However, I think it's not exactly what I want to do.
Look, in my case, the status is used as a signal in one instance. In your example, the status is used for all the instances, so you make it "static".
I usually read the code like that:
lock (this)<br />
{<br />
.....<br />
}
I think this is something similar to my case. Also if you read the help from C#.Net about the lock keyword, it said:
lock(expression) statement_block
expression
Specifies the object that you want to lock on. expression must be a reference type.
Typically, expression will either be this, if you want to protect an instance variable, or typeof(class), if you want to protect a static variable (or if the critical section occurs in a static method in the given class).
But I don't understand why I can not lock the variable which I want to protect. If I use this, how about two not related variables which I want to protect? When I lock "this" for "status", then another not related variable, let say "flag", it can not be changed either. It doesn't make sense.
Thanks again.
|
|
|
|