|
I'd changed the style to continous but it gives the same result as blocks
can u give me code example.
Syed Shahid Hussain
|
|
|
|
|
Hey everybody!
I'm trying to find an event that will be fired every time there is a change in the ROT.
Does anyone know about such a function (WIN32 API maybe?!) ???
If there is no such event I was thinking about creating a thread that will re-enum the ROT every 500ms and notifies me if there is such change, but I still hope there is a better way...
Thanks!!!!
|
|
|
|
|
Yesterday, I posted a message here about creating a modeless form with a single label control that was not being rendered by the form. Towards the end of the work day yesterday, we had all thought it might just be a problem on my computer (VS2005/SP1 on Vista). However, when I brought the code home and tried it, it happened there too (VS2005/SP1 on XP). It also happened on VS2008 using .Net 2.0 and then using .Net 3.5.
What's really disturbing is that two people here on CP tried the same code, and it did not occur for them.
--------------
This morning, I figured out how to force it to render the control. I added this function to the modeless form:
public void UpdateForm()
{
this.label1.BringToFront();
this.Update();
}
and then modified the code that opens/closes the form (remember, this code is in the DoWork() handler of a BackgroundWorker object) looks like this:
private void splashWorker_DoWork(object sender,DoWorkEventArgs e)
{
BackgroundWorker thisWorker = sender as BackgroundWorker;
SplashPanel splashPanel = new SplashPanel();
splashPanel.Show();
splashPanel.UpdateForm();
while (!thisWorker.CancellationPending)
{
Thread.Sleep(500);
}
splashPanel.Close();
splashPanel.Dispose();
}
I couldn't find ANYBODY ELSE on the net that had experienced the non-rendered controls problem that I've experienced. In the process of trying to figure t=out the problem, I tried using calls to MessageBox.Show() within various form event handlers, and discovered that the act of displaying a message box caused the label control to be properly displayed. Invalidating the control didn't have any effect. Hiding/showing the control didn't work. It was only out of desperation that I finally discovered that calling BringToFront() would show the control.
I want to know WHY this is necessary, or what is wrong with my Visual Studio (or .Net) install that would cause this problem.
[EDIT] I've come to the conclusion that this is a bug in the .Net framework, starting all the way back at .Net 1.0, and is probably related to the Event loop not being fired correctly. I added a bunch of other types of controls and all of them exhibited the same behavior as my original label control. Everything is fine as long as you are using a modal form (using ShowDialog() to display the form). However, displaying the form as modeless, you get screwed up up results.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Thursday, July 31, 2008 7:18 AM
|
|
|
|
|
HI all
Can any one tell or provide code for calling a c# dll(class library) from VB6.0 applicaiton
Thanks in advance,
urs friend
|
|
|
|
|
|
This code is working perfectly BUT am seeking help with the three possible error codes codes in the places numbered 1,2,and 3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Stackbuilder
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
stackTop = -1;
}
private int[] stackArray = new int[10];
private int stackTop;
private int val;
private int topValue;
private int peekValue;
private int k;
private void displayStack()
{
string nextItem;
displayBox.Clear();
for (int i = 0; i <= stackTop; i++)
{
nextItem = stackArray[i].ToString();
displayBox.AppendText(nextItem);
displayBox.AppendText("\n");
}
}
private Boolean emptyStack()
{
return (stackTop == -1);
}
private void displaybutton_Click(object sender, EventArgs e)
{
displayStack();
}
private void initbutton_Click(object sender, EventArgs e)
{
stackTop = -1;
displayStack();
}
1. // add error-checking code here
private void pushbutton_Click(object sender, EventArgs e)
{
try
{
val = Convert.ToInt32(valueBox.Text);
valueBox.Clear();
}
catch
{
MessageBox.Show("Please enter an integer.");
valueBox.Focus();
return;
}
stackTop = stackTop + 1;
stackArray[stackTop] = val;
displayStack();
valueBox.Focus();
}
2. //add error-checking code here
private void popbutton_Click(object sender, EventArgs e)
{
stackTop = stackTop - 1;
displayStack();
}
3. //add error-checking code here
private void topbutton_Click(object sender, EventArgs e)
{
topValue = stackArray[stackTop];
displayBox.Clear();
displayBox.AppendText("Most recently added item is \n");
displayBox.AppendText(topValue.ToString());
displayBox.AppendText("\n");
}
//add code here to implement peek function
private void peekbutton_Click(object sender, EventArgs e)
{
peekValue = stackArray[stackTop - 1];
displayBox.Clear();
displayBox.AppendText("The item below the most recently added item is \n");
displayBox.AppendText(peekValue.ToString());
displayBox.AppendText("\n");
}
}
}
|
|
|
|
|
Can you please explain a little what you mean by "Error Checking Code"
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Hello everyone,
Some URL representations, like "www.google.com" is not legal and will cause format exception when we use it to form URI class. In this specific case, it is because http:// is missing.
My questions are,
- Is what URI class doing conforming to industry standard about what is legal form of URL? Or URI class is doing something special to decide whether or not format exception will be thrown?
- Suppose we have URL strings like "www.google.com", how to make such strings "good format" to URI class? Any utilities' class to transform?
thanks in advance,
George
|
|
|
|
|
George_George wrote: Some URL representations, like "www.google.com" is not legal
That's because it is not an URL, its a hostname. Prefixing a protocol will turn it into an URL. IE and browsers, normally help the user out with this (by prefixing http:// automatically).
|
|
|
|
|
Thanks leppie,
Using IE is a manual solution. Is there any ways (e.g. .Net built-in class or some other samples) to automatically convert URL into good format?
regards,
George
|
|
|
|
|
I don't think there is one as it would never be definitive.
IE assumes http:// if it's ommitted, but it could be https://, ftp://, etc... etc...
You need to decide yourself what you expect and check/format it as needed.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks Dave!
1.
No reference document/samples and no built-in class to normalize a string to an URL?
2.
DaveyM69 wrote: You need to decide yourself what you expect and check/format it as needed.
Some manual work? No automatic way?
regards,
George
|
|
|
|
|
Is it possible to change the accessiblity of a property in code?
Why? I have a multi-function textbox class which has MinLength, MaxLength and RestrictionType (enum) properties.
1. If RestrictionType == Restriction.None the MinLength and MaxLength properties are read/write.
2. If RestrictionType == Restriction.IMEI I set the MinLength and MaxLength properties to 15. At this point I'd like to make MinLength and MaxLength read only as they shouldn't be changed while this RestricionType is active.
Obviously, at the moment I check the RestrictionType in the setters and reject the change if RestrictionType == Restriction.IMEI but I wondered if another way was possible.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi all..
I have created a dll in c# for crawling the documents from sharepoint and to get the modified date,created Date..etc..
When i run it from server where sharepoint is installed its getting the created date and modified Date....
But when i run it from client pc...It is giving Debug Error....
when i comment this code....which i used for getting created date and modified date...
the code is
using (SPSite RootSite = new SPSite(listPath))
{
Console.WriteLine("1Entered SPSIte path");
using (SPWeb SiteCollection = RootSite.OpenWeb())
{
string path = listPath;
SPFile file = SiteCollection.GetFile(path);
string TimeCreated = file.TimeCreated.ToLongDateString();
Console.WriteLine("1.1: Created Date is :" + TimeCreated);
}
}
when i comment this code it works fine....is there any problem in it...but the same code works fine in server pc...I am totally confused..please give some idea......I am totally new to sharepoint and c#
manju
Hi..
I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++
manju
|
|
|
|
|
manju#123 wrote: ...It is giving Debug Error....
What is the error?
Post the full error details and stack.
Simon
|
|
|
|
|
Simon Stevens wrote: Post the full error details and stack.
Hi ..
It is showing the pop up window and the error is...
Debug Error!
The application has requested the Runtime to terminate it in an unusual way.Please contact the applications support team for more information
thank you
manju
Hi..
I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++
manju
|
|
|
|
|
I'm writting an application that makes several instances of Internet Explorer object to render webs and record the content. To make the video it's very easy 'cause I can take snapshots of the web rendering, but I don't know how I can record the sound of different sites simultaneously.
Thanks a lot!
|
|
|
|
|
Fields that are declared volatile are not subject to compiler optimizations that assume access by a single thread This is from the VS help about the volatile keyword in C#.
Does that mean normal variables are cached and to optimize speed, the cached value is used unless the variable is changed in the current thread?
And volatile means, that no cached values are used but before every operation, the value of the variable is read again?
Then, the concept of a a volatile variable is that the value a Thread reads from it is always up to date and now possibly outdated like a normal variable?
BUT, what about larger variables, like long or even objects?
Wouldn't it still be possible that while one thread reads the first byte of a long, another thread writes the second byte?
So, the first thread would still have an outdated value of the variable?
Thanks.
|
|
|
|
|
Megidolaon wrote: Does that mean normal variables are cached and to optimize speed, the cached value is used unless the variable is changed in the current thread?
Yes, sometimes.
Megidolaon wrote: And volatile means, that no cached values are used but before every operation, the value of the variable is read again?
Yes.
Megidolaon wrote: BUT, what about larger variables, like long or even objects?
Wouldn't it still be possible that while one thread reads the first byte of a long, another thread writes the second byte?
Yes. Accessing a long is not guaranteed to be atomic.
To read larger types atomically, use the methods in the Interlocked class.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yes, normally the JIT compiler can generate code that reads a value from memory into a register, then reuse that register everywhere without referring back to the original memory location.
However, even generating code that loads the memory location into a register every time may not help. The reason is that modern processors have a hierarchy of caches, and typically have a buffer of pending writes so it can combine small writes into one larger transaction. This is because the system memory has quite a lot of latency to open one memory location, but once it's open, a small number of subsequent locations can be accessed quite quickly. The overhead to keep all the caches always synchronized would be quite extensive, so it isn't done.
The result is that the processor will just read the value from its own cache rather than go back to main memory, unless you explicitly tell it that it must go back to main memory, and at the same time to tell other processors in the system to flush this location from their write buffer. This is referred to as a 'memory fence' or memory barrier[^].
Using the volatile keyword in C# will cause acquire and release barriers to be generated appropriately. In C and C++ the semantics only suppress compiler optimizations; they do not generate memory fences. The JIT compiler will generate the right code for the type you're using.
On x86 processors, since the Pentium, variables up to 64 bits in size that are aligned correctly (which they will be, by the JIT compiler, unless you use StructLayout attributes to explicitly set the alignment) are always read atomically, so you don't need to worry about partial reads of long variables. Pentium Pro and newer processors will perform unaligned reads atomically as long as it remains within a single cache line (the unit of access to cacheable areas of main memory).
For objects, volatile applies to the object reference, not the object itself. You cannot apply volatile to a user-defined structure.
See also Raymond Chen's article High-performance multithreading is very hard[^]. In general, stick to Monitor or the lock keyword (which just calls Monitor.Enter and Monitor.Exit for you) until you can prove that the lock is too much of a bottleneck.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Thanks a lot, that was quite informative.
The main reason I made this topic is because I read aborting a thread by periodically checking a volatile bool is a good way to do it.
In the case of a bool, is it truly reliable that by the time the value is read, it is up to date?
Also, is there a better way to check for the cancellation request other than wrapping each 5-10 operations in an if statement?
And now I have a whole new problem, I was testing around with the lock keyword and noticed something I don't like at all.
class Program
{
static List<string> list = new List<string>();
static void Main(string[] args)
{
Thread t1 = new Thread(new ThreadStart(DoSomething));
Thread t2 = new Thread(new ThreadStart(DoSomethingElse));
t2.Start();
t1.Start();
Console.ReadLine();
}
static private void DoSomething()
{
Thread.Sleep(13);
for (int i = 0; i < 100; i++)
{
list.Add("1");
Console.WriteLine("1");
if (list.Count< 100 && list.Contains("2"))
{
Console.WriteLine("FIRST LOCK BREACHED!");
break;
}
}
Console.WriteLine("1-Count: " + list.Count.ToString());
}
static private void DoSomethingElse()
{
lock (list)
{
for (int i = 0; i < 100; i++)
{
list.Add("2");
Console.WriteLine("2");
if (list.Contains("1"))
{
Console.WriteLine("SECOND LOCK BREACHED!");
break;
}
}
Console.WriteLine("2-Count: " + list.Count.ToString());
}
}</string></string> This will produce random output, it seems the threads get different time slices every time I execute the program, how come?
Also, sometimes it will produce this output:
...
2
1
FIRST LOCK BREACHED
1-Count: 19
SECOND LOCK BREACHED
2-Count:19 This is confusing me, because I thought lock actually blocks other threads. However that is apparently not the case.
Thread 1 always starts after thread 2 and since thread 2 locks "list", thread 1 should have to wait until thread 2 is done, but apparently it slips in somewhere in between and still accesses the list.
By the time thread 2 writes to the list, it is empty but 3 lines below, when it checks if the list contains a "1", it really does. Why does that happen?
And I tried the same with wrapping all of thread 1's work in a lock of "list", in that case everything will be executed in order, no matter how many times I test it.
I'd really appreciate if you could clear this up.
Thank in advance.
|
|
|
|
|
You must always lock a data structure consistently, before reading as well as writing. Your function DoSomething must lock. A sleep will always be the wrong length and is never, ever the right solution to a race condition. What I mean is, in some circumstances the sleep won't be long enough for the other condition to complete; in others, the operation will complete early and the sleep just wastes time.
Locks only block another thread if the two threads explicitly lock the same data structure.
Megidolaon wrote: This will produce random output, it seems the threads get different time slices every time I execute the program, how come?
Because thread scheduling depends on the load of all the other things going on in the system. Just moving the mouse slightly differently can have an effect.
If you don't understand locks I would recommend steering well clear of lock-free programming.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Megidolaon wrote: This is confusing me, because I thought lock actually blocks other threads. However that is apparently not the case.
No, the lock doesn't lock other threads, it only locks other locks. As you only have one block of code that is locked, the lock has no effect.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
First of all, i wrote execly the same Subject yesterday but i didnt understand the answer..
i want to add a new row to specific MDB file...
my code is:
string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source =" + Dir;
string commandString = "Select id,Event from Events";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandString, connectionString);
DataSet ds = new DataSet();
dataAdapter.Fill(ds, "Events");
DataTable datatable = ds.Tables[0];
DataRow newRow = datatable.NewRow();
newRow["id"] = "aaa";
newRow["Event"] = "bbb";
datatable.Rows.Add(newRow);
dataAdapter.Update(ds, "Events");
ds.AcceptChanges();
Application.DoEvents();
i did this code but it pop a exception:
"Update requires a valid InsertCommand when passed DataRow collection with new rows"
What i need t do? and where?
thank you very Much
G.
modified on Thursday, July 31, 2008 3:59 AM
|
|
|
|
|