|
Determines whether the List contains elements that match the conditions defined by the specified predicate.
(from MSDN)
|
|
|
|
|
|
Hi
The following code declare the predicate match method in the employee class.
in order to check if employee instance exists within the list, just construct new employee class with the relevant parameters (i used id as key) and call the Exists method
class Program
{
class Employee
{
private long m_id;
public Employee(long id)
{
m_id = id;
}
public bool IsMatch(Employee employee)
{
return (m_id == employee.m_id);
}
};
static void Main(string[] args)
{
List<employee> employees = new List<employee>();
employees.Add(new Employee(1));
employees.Add(new Employee(2));
employees.Add(new Employee(3));
employees.Add(new Employee(4));
employees.Add(new Employee(5));
Console.WriteLine(employees.Exists(new Employee(3).IsMatch) != null);
}
}
|
|
|
|
|
Thanks!. for alternative solution.
|
|
|
|
|
Hi,
I have a problem in that I have a function as follows:
public void Init()<br />
{<br />
DoSomething();<br />
DoSomethingElse();<br />
<br />
MyObject obj = new MyObject();<br />
obj.Var1 = "Test";<br />
obj.Var2 = 123;<br />
}<br />
Now when I step through the code it stops debugging at the point of entering Init() in the calling event. By stops debugging I mean all execution appears to stop and it hangs, it does not even step into the Init() function but if I remove the '= new Object()' it will step into the function and execute the two top methods before giving a NullReferenceException as you would expect.
So my question is; what make the creation of a new object stop the entire enclosing method from executing?
|
|
|
|
|
Hi DanC,
Is MyObject a class(public or private) and Var1 and Var2 are class variables that u r accessing with the object instance of that class ? If that is so, then I would say the code ideally works fine, it steps into the function when called by an event lets say button click, this is what i wrote
<br />
private void button2_Click(object sender, EventArgs e)<br />
{<br />
Init(); <br />
}<br />
public class MyObject<br />
{<br />
public string Var1;<br />
public int Var2;<br />
}<br />
public void Init()<br />
{<br />
MyObject obj= new MyObject();<br />
obj.Var1 = "Test";<br />
obj.Var2 = 123;<br />
}<br />
and it is running fine, I think the execution on ur side is exiting the application, try and analyse the code further and let me know
|
|
|
|
|
MyObject is a public class from an external class library, I am setting both vars and adding event delegates in the Init() function. I am executing it as you describe above but it will only step in if the 'new MyObject()' line is not there.
With the line 'MyObject obj = new MyObject()' in the code when I step into that function all debug buttons are greyed out apart from stop, pause and restart and it does not step into the function, however if I comment out the ' = new MyObject()' it does step into the function and executes the DoSomething() and DoSomethingElse().
I do not change anything other than commenting out the ' = new MyObject()' to make it step into the code.
|
|
|
|
|
Hi,
who is calling Init ? some constructor ?
is it a first time call ?
has MyObject class already been called (hence compiled by JIT) ?
Any chance MyObject can not be found at run-time (separate DLL maybe ?).
Please show code for MyObject (at least: members and constructor).
|
|
|
|
|
Init is being called by the Start event of the main class for the app.
It is a first time call.
MyObject has not been called before but I have left the app for 10 mins and it is still hung so I would think it unlikely it was the JIT compiler.
I would expect to see an exception if the class could not be found rather than the app hanging but the class is in a referenced DLL next to the app.
I cannot show the code for MyObject as it is a third-party .NET assembly.
|
|
|
|
|
Hi
did you try using a try / catch block in order to catch exception ???
|
|
|
|
|
I have a try...catch block inside the Init() function to catch the exception but the problem is that the execution does not enter the Init() functio if that line exists so therefore no exception is thrown.
|
|
|
|
|
use the try catch before the call to the init function
|
|
|
|
|
I should have mentioned, I have also wrapped the Init() in a try...catch but again, nothing, no exception, nothing, just a hung application.
|
|
|
|
|
OK sorry
Can you give more details about the MyObject class ????
and the environment that your application running ???
thanks
|
|
|
|
|
The environment is Visual Studio 2003, .NET 1.1, Windows XP.
The MyObject class is a third-party assembly containing lots of system calls, I understand that the problem could well be within the assembly and not my code and therefore out of my reach to fix but I would like to understand how a problem in a DLL assembly could stop the debugger entering the calling function, I could understand if it hung on the constructor of the MyObject class but I cannot see how it could hang on the calling function.
|
|
|
|
|
I run into some problems with the debugger (crushes,hangs and so on)
usually while doing some system programming, the solution to that in most cases was just restart.
you can try one of the following:
1.try to debug on another machine (check that you don't have problem in your environment)
2.use the System.Diagnostics.Debugger.Break(); command in order to force break.
3 use the sos debug extension in order to examine the runtime steps at execution
4 restart your computer and try again
|
|
|
|
|
turn MyObject class to a static one, if you cannot, i think i had the same problem with DirectX, where i tried to identify a class which contains a directX identifications. it threw me a bizzar exception. and what i did is putting a breakpoint and run the program pressing F10, at first, it threw me an exception but thenit ran normally. try that. it's so fool but you don't encounter this exception in *.exe file!
|
|
|
|
|
OK,
now what is MyObject class supposed to do ?
any idea what would be inside its constructor ?
have you other apps that use MyObject successfully ?
|
|
|
|
|
The MyObject implements a set of delegates which attach to system events allowing them to be handled by a .NET 1.1 application which they would otherwise not be able to do.
I have no idea what would be in the constructor unfortunately but on further testing I have found that a call to a static function within the class prodcues the same result so I am confident it is an issue with the assembly but that still doesn't get me any closer to why the entire function does not execute.
|
|
|
|
|
OK, sounds like there is a problem with a static initializer in MyObject. I can see
two ways forward now:
- contact the author
- try figuring out what is in the initializer using Reflector.
I assume you are on .NET 2.0 or 3.x; you might want to try MyObject inside a .NET 1.1
project, just to see if it works for you; the simplest invocation of MyObject should
be sufficient.
BTW I am not impressed by a "third party" that calls its stuff "MyObject".
Good luck !
|
|
|
|
|
It's not called MyObject, I just used that to demonstrate the problem I would be equally unimpressed if it were
It is currently in .NET 1.1, the assembly and my project are both 1.1.
I've contacted the author and waiting on a reply.
The question I was asking more than what could be wrong with the assembly as I realise it is the assembly causing the problem is how that problem could cause my function not to be executed even before any calls are made to the assembly, I would expect it to fail at the point of referencing the assembly but at least execute the function calls above it.
|
|
|
|
|
__DanC__ wrote: I would expect it to fail at the point of referencing the assembly but at least execute the function calls above it.
I understand that is what would be expected, but when you reach the Init() method, the
first thing that happens is the JIT compiles it; so it wonders about the
MyObject class, it must locate it, and at some point in time, also statically initialize it.
I am not sure exactly when that is supposed to happen; it must be deterministic of course,
and I know the exact order is surprisingly complex; long time ago I suffered from
a bug in that area, dont recall whether it was in 1.0 or 1.1 tho.
I think it is safe to assume static constructors get executed at the start of the
calling method (your Init), since the JIT in general must cope with a complex
flow graph and multiple references to the class, so it cannot always
(and hence does not even try to) predict which one will occur first, hence it will go
for early initialization.
You could proof this true or false by pushing the MyObject stuff and following code
inside Init() one level deeper...
|
|
|
|
|
hi,
i have a unmanaged c++ app that sends events to a managed wrapper, and then the wrapper sends it to my c# app. it works fine. but now i want to create custom controls that gets these events. the problem is i have no idea how. i can create basic custom controls and so.
it's for a touchscreen, so what i want to do is very similar to the click/mousedown events, except its more of a touchdown instead of mousedown.
eventually i want to be able to do Image.touchdown += (add event handler) and one the image is touched on screen, the event is raised. just like a mouse event.
can anyone please tell me where to start, or what article to read, or just give me a hint in the right direction?
thanks,
donovan
those that say it cannot be done shouldn't interrupt those doing it
|
|
|
|
|
With touch screens doesn't the touching equate to mouse stuff?
i.e. if you tap it's like doing a click.
|
|
|
|
|
it's for a multitouch screen, so pressing two fingers on an image does do quite different things than pressing two fingers on something else. so emulating the mouse is not quite a good solution
rather have something you don't need, than need something you don't have
|
|
|
|