|
I have tested a case of three "1", and the result is position "1", and for four "1", the result is position "2".
So, may be the question should be should conditions must be there before we consider binary search?
With love,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
In the following code, I use a a DataView to find all the records in my table that meet criteria X. I then change the value in the DataRowView so that they no longer meet criteria X.
After I change a couple of DataRowViews, I get an exception that my index is out of range. It looks like the DataView object is updating the Table, and re-evaluating the RowFilter criteria, and updating itself. So, there's now less DataRowViews in my DataView, and my index is incorrect.
Can that really be happening? Are you not supposed to modify the DataView? Or should I be locking it somehow?
private void ClearCurrentSetInPlayistTable()
{
// goes through the Libraries And Playlists Table, setting
// any playlist whose IsInCurrentSet col value is true, to false
DataView dv = new DataView(dtLibrariesAndPlaylists);
string strRowFilter = IsInCurrentSet + " = true";
dv.RowFilter = strRowFilter;
int dvRowCount = dv.Count;
for (int i = 0; i < dvRowCount; i++)
{
DataRowView drv = dv[i];
drv[IsInCurrentSet] = false;
}
}
Thanks,
Joe
|
|
|
|
|
My original suspicion is correct, and is valid behavior.
By modifying the DataViewRow, I'm modifying the underlying table. This causes all of the DataView "children" from the table to be updated, and the count of rows in my DataView goes down.
I could get around this problem by putting the actual row count, and not a copy of it's initial state, into my loop statement. Instead of:
int dvRowCount = dv.Count;
for (int i = 0; i < dvRowCount; i++)
{
DataRowView drv = dv[i];
drv[IsInCurrentSet] = false;
}
I would just use
//int dvRowCount = dv.Count;
for (int i = 0; i < dv.Count; i++)
{
DataRowView drv = dv[i];
drv[IsInCurrentSet] = false;
}
However, since the update to the DataView is coming in asynchronously, this might still fail.
The real solution here is to use a Table.Select() instead of a DataView here. The set of rows returned by the Select are static, and aren't updated by changes to the underlying table.
|
|
|
|
|
I have a ToolStripDropDownButton, which drops a menu. During run time, my code adds a dropdownmenu to each of those items, ala:
// top level menu item is A
// submenu is B
B = new ToolStripMenuItem(); // new menu item
B.Text = "Checkable Sub Menu";
A.DropDownItems.Add(B);
To A, I will add a dynamic number of DropDownItems. Later, in code outside of this scope, I need to handle the CheckStateChanged event for those items. How do I code a handler for them?
If I've added B in the Designer, then I can easily write the handler using the name:
private void B_CheckStateChanged()
However, since these items are created on the fly, how do I can I write a handler that doesn't need to know their name?
I'm working in C#, if it's not clear. TIA for the help.
|
|
|
|
|
You can specify the event handler for B before adding it to A
B.CheckStateChanged += new System.EventHandler(CheckStateChanged);
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
Thanks for the quick answer!
I'm still a little confused, though. It looks like you are specifying a type of handler, and not a specific instance of a handler?
In other words, did I write a handler somewhere, that is being called when B.CheckStateChanged fires for B?
And what did it look like (the declaration)?
Thanks!
|
|
|
|
|
I am sorry, I shouldnt have used the Event name
B.CheckStateChanged += new System.EventHandler(CheckStateChanged_Event);<br />
<br />
void CheckStateChanged_Event(object sender, System.EventArgs e)<br />
{<br />
}
I guess this makes it clearer
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
I think I'm starting to get it. I posted a more generalized question over in C# based on this.
My question really deals with writing handlers when you can't know the name of the object ahead of time, as when you create arbitrary controls like above.
I think you may have answered it. If B supports a CheckStateChanged property, and it changes, then the CheckStateChanged_Event handler will fire, and I'll be able to look at the Sender to see which item changed, and look at the sender.CheckState to see what the new state is?
Again, thanks for helping me past my ignorance. The .NET framework is fairly new to me. As is C#, sort of. Seriously, I rely way too much on Intellisense to let me know what's available...
|
|
|
|
|
JoeRip wrote: I'll be able to look at the Sender to see which item changed, and look at the sender.CheckState to see what the new state is?
You could use the Text or the Name property to identify the sender and accordingly write a switch block or an if condition.
((ToolStripMenuItem)sender).Text;<br />
((ToolStripMenuItem)sender).CheckState
JoeRip wrote: Again, thanks for helping me past my ignorance. The .NET framework is fairly new to me. As is C#, sort of.
Just have a look at the articles available on this site, you can gain tremendous amount of knowledge.
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
Consider the following:
namespace Lesson2
{
class Program
{
static void Main(string[] args)
{
System.Threading.ThreadStart oThreadStart;
oThreadStart = new System.Threading.ThreadStart(UpdateCount);
System.Threading.Thread[] oThreads;
oThreads = new System.Threading.Thread[10];
for (int i = 0; i < oThreads.Length; i++)
{
oThreads[i] = new System.Threading.Thread(oThreadStart);
oThreads[i].Start();
}
// Wait for them to complete
for (int i = 0; i < oThreads.Length; i++)
{
/*
* The different threads in 'oThreads' use the same
* variable 'Counter.Count'.
* => The variable 'Counter.Count' is shared by these threads.
*
* Without 'Join' the 'WriteLine' does his work before the
* last thread is done.
* => Total is less then 100.000.
*/
oThreads[i].Join();
}
/*
* Show to the console the total value of 'Counter.Count'
*(after the 10 threads)
* Should be 10 * 10.000 = 100.000
*/
Console.WriteLine("Total: {0}", Counter.Count);
Console.ReadLine();
}
static void UpdateCount()
{
for (int i = 1; i <= 10000; ++i)
{
Counter.Count = Counter.Count + 1;
}
}
}
public class Counter
{
public static int Count;
}
}
The expected 'Total' that is written to the console is '100.000' (10 threads that increment 'Counter.Count' with '10.000').
The book i'm currently reading
(http://www.amazon.com/MCTS-Self-Paced-Training-Exam-70-536/dp/0735622779)
says that if you run this code on a hyperthreading- or a multiprocessorsystem
the 'Total' that is written to the console will sometimes be less than '100.000'. I don't understand the explanation.
|
|
|
|
|
The potential problem on a hyperthreaded or multi-processor PC is due to the fact that each processor in a PC maintains its own cache. Therefore, if any of the threads executing in your routine happen to run on a different processor, that processor updates its own cache and does not automatically publish the new value to the other processor. This would cause your counter to 'miss' that particular iteration of the counter.
There are several potential solutions to get around this, for instance using the VolatileRead and VolatileWrite methods of the Thread class (these use shared memory that all processor's can access, rather than storing the value of your variable in a CPU register) or using the MemoryBarrier of the Thread class (this method flushes the caches and CPU registers of all the processors into memory, ensuring that variables contain current data). You can get plenty of info on the Thread class and it's methods on the MSDN website.
Hope that helps.
|
|
|
|
|
|
hi , i use from from Shockwave Flash Component in visual studio 2003 without any problem but in VS 2005 whene i want add Shockwave Flash Component to a form,VS2005 show a Error and say i should register "Shockwave Flash Component". please help me.
|
|
|
|
|
How can I get a reference of the calling Assembly at Runtime?
I've an assembly (RestrictedAssembly) and I want to ristrict access to it means no user who
fullfills my criteria (in my case not having my desired public key token for assembly) can
instantiate any type from my assembly.
For better understanding, this is what I am trying to do.
I've generated a public/private keypair file for myself, then I use it to sign all those assemblies
which I want to allow Access to my RestrictedAssembly. On Runtime before instantiating any type from
RestrictedAssembly, in constructor I am asking the caller to provide a Type object from which he's
initiating a call to constructor. For example.
public RestrictedType1(Type o) {
Type t = this.GetType ();
byte [] t1Token = o.Assembly.GetName().GetPublicKeyToken();
byte [] t2Token = t.Assembly.GetName().GetPublicKeyToken();
AccessNotAllowedEx ex = new AccessNotAllowedEx("Not Allowed");
if(t1Token != null && t2Token != null) {
if(t1Token.Length == t2Token.Length) {
for(int i = 0; i< t1Token.Length; i++) {
if (t1Token[i] == t2Token[i])
continue;
else
throw ex;
}
ex = null;
} else
throw ex;
} else
throw ex;
}
I am checking, if the public key tokens for both the calling and called assemblies are identical and
if they are, then I am allowing the caller to instantiate my RestrictedType other wise I raise an
exception.
Now the problem with this approach is that, suppose I've an Assembly CallerOfRestrictedAssembly and
I've signed it with my public/private key pair. Now from CallerOfRestrictedAssembly it is valid to
do the following. Since both assemblies have same public key token.
RestrictedType1 res = new RestrictedType1(this.GetType);
However, suppose if some one initiate a call to RestrictedType1 constructor
RestrictedType1 res = new RestrictedType1(typeof(TypeFromCallerOfRestrictedAssembly));
This will cheat the constructor. Thus, I don't want caller to Pass Type argument into Constructor.
and depend on it. What I am looking for is to get a reference of Calling Assembly into my
RestrictedAssembly at Runtime?
I'll apreciate if some can help with this or any other approach to achieve this level of code
restriction? Thanks.
SMK
|
|
|
|
|
Please don't cross post.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Can anybody help me to understand and use 'ExecutionContext'
(or give me za good link)
|
|
|
|
|
I am curious as to what would be the best method to determine the memory allocation footprint of a filled dataset object.
Can anyone point me in the right direction?
|
|
|
|
|
I got this question in a tech interview,
tell me any one ARCHITECTURAL DIFFERENCE between .net 1.0 and 2.0?
can you guys list out a few please??
|
|
|
|
|
karam chandra bose wrote: ARCHITECTURAL DIFFERENCE between .net 1.0 and 2.0
Here is from wiki... http://en.wikipedia.org/wiki/.NET_Framework[^]
If you try to write that in English, I might be able to understand more than a fraction of it. - Guffa
|
|
|
|
|
Well, there's generics and nullable datatypes for a start.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi all,
What is the best pratice / methods / or technologie to be used to create a GUI interface that will be connected to a windows service written in .NET/C#.
I need to display buttons that will trigger some actions on the service, a listbox-like controle that will trace log from work done on the service and so on...
Do you have any idee on how to do this ?
Thanks
|
|
|
|
|
Well, I have a control I use for viewing the states of services which has buttons for Start and Stop.
You can add custom actions to a service, but I don't know if you can get data back from a service directly. Or maybe use remoting?
The best I have is a service that creates an XML file that another application uses.
|
|
|
|
|
Hi PIEBALDconsult,
In fact I want to remotely start a Form hosted by the service.
The Form will have Button, Checkbox and Log-list that would permit to change the behavior of the service. For example: change the trace level, call a special methode, set/change some values...
You are right, I could use Remoting with a interface. But I don't want to change the interface, for example every time I add a new button to the form.
Rather than calling a Method, I need to instanciate a assembly remotely or
in other words, I need a little VNC functionality on a Form.
Does anyone has an Idea ?
Christophe
|
|
|
|
|
Hi,
I am unable to edit my Data grid. I also wants to change my width of edited text box.
Thanks & Best Regards
Manvendra Kushwaha
Software Developper
|
|
|
|
|
hi ,
goto datagrid property builder and add bound colums . each bound colum heder text,databoundcolum . type name in the header text colum and type database field name in the data field . after convert into template colum . and write this code to edit the textbox
//inside event
Edit_Click
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
Bind();
}
Bind Method is for Bind the data to datagrid Common code
right click the datagrid and go to edit template column there u wil l find the text box and gotot properties and change width
i thnk htis will help u.
thanks and regards
kinnu
kinnu
|
|
|
|