|
If you scroll up to the top of this page you will see a list of all the programming forums try in the c++ one. You don't need to put an email address, you will be notified when someone answers your question in the forum.
I apologize for being harsh, I've never understood why people ask questions here and then at the bottom tell people to reply to them directly by email and I get a lot of emails directly from people about my articles instead of asking in the article message board which annoys me completely. It's probably only pissed me off, just re-ask your question in the correct message board and someone will answer it if they can there.
|
|
|
|
|
thanks alot it ok i understand
|
|
|
|
|
Hi all,
I would like to do a database testing, like testing the Stored procedures. Could anyone guide me?
|
|
|
|
|
Roy Osherove's got a great free project, XTUnit[^] that provides a way to unit test database access (stored procedures, views, etc.) and still rollback any changes made during the unit test.
|
|
|
|
|
|
Hi,
I have not done StackTrace stuff like that, but here are some facts and ideas:
1)
the documentation says "If a StackTrace is created with a target thread that is not the
current thread, the target thread must first be suspended"
Well, suspending the UI thread is not a good idea (if it is all possible); and I would
not be surprised if you would fail to suspend it when your app is "Not Responding".
Anyway it sounds like a bad idea if you already have UI problems...
2)
AFAIK the "Not Responding" mechanism is as follows: Windows kernel periodically sends a special
WM_xxx command to each application, and expects a return message within a short delay
(similar to the ping protocol over a network). Normally that message gets handled by the
message pump (normally the UI thread), unless the app is too busy (long calculation
on UI thread), is waiting on something, or hangs in any other way.
3)
This also means I cannot predict the ThreadState of your UI thread.
4)
Thread priorities:
if your app uses multiple threads, carefully choose their priority; at or below normal
should not pose problems; above normal should be used carefully, and real-time is to
be avoided (except for short and very specific loop- and wait-free code).
Rationale: when two threads are ready to run, Windows would allot most CPU cycles to
the highest priority one, and some CPU cycles to the lower priority one too, but if that
is the UI thread you would call it unacceptable responsiveness. (And I expect this to
be even worse on a Windows Server OS).
A real-time thread would consume all CPU cycles.
5)
sometimes a small UI problem can be solved by including some
Application.DoEvents(); statements inside a busy loop. I am not sure this is a clean
solution, but it occassionally improves the UI behavior.
6)
My advise: try one or more of the following:
- watch the Task Manager's "Performance" tab while your app is, if possible, the only one
really running. If CPU load is high, it looks like either real calculation, or a polling
loop that lacks a delay; if they are in the UI thread, they should be moved in another thread;
if they occur in a higher priority thread, they would severely reduce UI responsiveness.
- use some other observation tool (e.g. "task info", not part of Windows) that can give you
an indication of CPU load per thread; although identifying threads within a process is
not easy, I expect the UI thread to be the first (or one of the first).
- run your app inside Visual Studio, pref. in debug mode, and pause the app while the
non-responsiveness begins; if this brings up a source file (or a useful call stack)
that is the suspect code.
- if you can find the code that causes the problem:
if it is real calculations, they must move to another thread, with a priority at or
below normal; if it is a wait (anything that blocks or could block), it does not belong
in the UI thread. The UI thread should never block ! (I know this is not easy, it also
means it should not lock).
Hope this helps
Luc Pattyn
|
|
|
|
|
Hi
I've got a problem...
I developed a program taht downloads the sourcecode of a website and checks it for a special string (a picture-name in my case).
I'm using this to download the website:
WebClient client1 = new WebClient(); <br />
client1.DownloadFile("http://" + lVsm.CheckedItems[i].ToString() + ".xxxxxx.xxxxxxx.de", Application.ExecutablePath + "/temp.txt");
In the second line the framework tells me "URI formats are not supported".
I already tried a stream but it didn't help.
|
|
|
|
|
What is lVsm.CheckedItems[i] ? What data type is it? What value does it contain? Does converting it to a string result in a meningful value?
---
single minded; short sighted; long gone;
|
|
|
|
|
When a single but complex line fails, the first attempt to understand it is
to split the line and look at the intermediate values, like so:
string s1="http://" + lVsm.CheckedItems[i].ToString() + ".xxxxxx.xxxxxxx.de";
string s2=Application.ExecutablePath + "/temp.txt";
Console.WriteLine("s1="+s1);
Console.WriteLine("s2="+s2);
client1.DownloadFile(s1, s2);
Chances are you will immediately see what is wrong.
If not, include the output in your post.
Luc Pattyn
|
|
|
|
|
hi,
i was using to conver a string into HttpUtility.UrlEncodeUnicode("string value"), its working fine web application, but when i tried to run in windows forms application , it says httputility does nt exist in current context, i m using this format in crawling.
please need quick help.
many thanks, adnan
|
|
|
|
|
The .NET classes reside in many namespaces; most namespaces need to be added
(add reference) and declared (using ... at the top of your files).
Visual Studio will add some references and some using statements, depending on
the type of project you create. But you can always add to them, so find out what
it is you need, either by reading the documentation on the classes you are
interested in, or by looking at another project that uses them and does compile.
Luc Pattyn
|
|
|
|
|
bundle of thanks, Adnan
|
|
|
|
|
Please do remember to use the HttpUtility class, you need IIS running, ie. you need a webserver. your windows application may not have this as prerequisite as happens in most cases.
So this is not a good class to use in Windows application.
Pradipta Basu
|
|
|
|
|
how do I check if my application is already runnig when I open it?
cheers!
|
|
|
|
|
There are some articles here on CP that cover this topic. You should be able to find them by searching for "single instance".
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
search codeproject for "singleton application" or something like that, there are many
articles on it.
Luc Pattyn
|
|
|
|
|
Hi,
I'm looking for graphic library which make possible fast copying part of image and pasting this sample to another image in selected position. I need it for implementing some texture synthesis algorithm. If you know such a library, I'll be grateful for any help.
|
|
|
|
|
Have you tried anything, what was the problem ? and what is "fast" ?
I would suggest you experiment a bit with GDI+ and form your opinion based on that;
then, if still necessary, start looking for specific things.
Luc Pattyn
|
|
|
|
|
GDI+ will copy part of an image on top of another image.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
The GDI+ library works realy fast, how fast it can be, I'll see tomorow
Thanks for indication me the right path, previously I convert a Bitmap to byte array and work with it. It have caused many problems with image stride.
|
|
|
|
|
Yeah, if you access the stride, it will blow up. It's good for image processing, for drawing, you're better off trusting GDI+ to know what it's doing.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi,
I would like to deserialized in class and XML document which can be found on this URL : http://ws.audioscrobbler.com/1.0/artist/Metallica/similar.xml
Here is my two class to deserialized this XML but i've got a problem. After deserialization, i've got in attributes SimilarArtists.artists a list of 100 artists (which is good) but all artist's attributes are null (for string) or zero (for int).
There's something wrong but i don't see..
maybe someone can see something that i can't ?
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Net;
using System.IO;
namespace Xtream_ToolBox.Sensors {
[XmlRoot("similarartists")]
public class SimilarArtists {
[XmlIgnore]
public List<Artist> artists = new List<Artist>();
public SimilarArtists() {
}
public static SimilarArtists loadFromUrl(String url) {
SimilarArtists similarArtists = null;
Uri uri = new Uri(url);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(SimilarArtists));
try {
WebResponse webResponse = HttpWebRequest.CreateDefault(uri).GetResponse();
Stream stream = webResponse.GetResponseStream();
similarArtists = (SimilarArtists)xmlSerializer.Deserialize(stream);
stream.Close();
} catch (Exception e) {
Console.WriteLine(e.Message);
}
return similarArtists;
}
[XmlElement("artist")]
public Artist[] artistArray {
get {
Artist[] artistArray = new Artist[artists.Count];
artists.CopyTo(artistArray);
return artistArray;
}
set {
if (value == null) return;
Artist[] artistArray = (Artist[])value;
artists.Clear();
foreach (Artist artist in artistArray) {
artists.Add(artist);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace Xtream_ToolBox.Sensors {
public class Artist {
[XmlAttribute("name")]
public String name;
[XmlAttribute("match")]
public int match;
[XmlAttribute("url")]
public String url;
[XmlAttribute("image_small")]
public String imageSmall;
public Artist() {
}
}
}
-- modified at 6:53 Saturday 3rd February, 2007
nobody has an idea ?
|
|
|
|
|
I am pretty new to c# and I'm writing my thesis on Bio Sequence Alignment So I have alot to do with generating random strings.
This is a *very cut down version of my problem, it is the shortest snippet that explains my predicament.
namespace MyConsoleApp
{
class Program
{
static void Main(string[] args)
{
MyClass fred = new MyClass();
MyClass jim = new MyClass();
fred.generate();
jim.generate();
Console.WriteLine(fred.MyString);
Console.WriteLine(jim.MyString);
Console.ReadLine();
}
}
public class MyClass {
private Random rand;
public string MyString;
public MyClass()
{
this.rand = new Random();
}
public void generate()
{
StringBuilder tempString = new StringBuilder();
for (int i = 0; i < 6; i++)
{
tempString.Append(getRandomChar());
}
this.MyString = tempString.ToString();
}
private char getRandomChar()
{
int num;
num = getRandomInt(0, 2);
if (num < 1) { return 'A'; }
else if (num < 2) { return 'B'; }
else { return 'C'; }
}
private int getRandomInt(int lower, int upper)
{
if (lower > upper)
{
int temp = upper;
upper = lower;
lower = temp;
}
else if (upper == lower)
{
return upper;
}
return (rand.Next() % (upper - lower + 1)) + lower;
}
}
}
I believe this should print out two completely different strings but in reality it prints out two identical strings.
Why oh why is this happening?
More than a solution to this exact problem I wouldn't mind learning what subtle point of c# is causing this.
Oh, and a solution would be good too...
Cheers.
|
|
|
|
|
Put a delay in between your constructors. Random is getting seeded with the same time, so it's not very random for each "generated" class.
Better yet, use a common Random class, so it gets seeded only once. There's no reason to create multiple Random classes with what ends up being the same seed because the code executes so fast the time doesn't change.
Marc
Thyme In The CountryPeople are just notoriously impossible. --DavidCrow There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith
|
|
|
|
|
Well, you're getting the same sequence of random numbers.
You either need to have the constructor specify a seed, or...
What I suggest, in this case, is to make the Random static so all the instances of MyClass use the same instance of Random
private static Random rand = new Random();
You may then need to have MyClass lock the Random when it uses it
<br />
lock ( rand )<br />
{<br />
return (rand.Next() % (upper - lower + 1)) + lower;<br />
}<br />
|
|
|
|