|
|
This is the answer:
https://stackoverflow.com/a/55632847/579381
thanks anyway.
|
|
|
|
|
HI,
I have one circle with radius & center point, I have to place multiple circles with radius known but center point unknown (needs to be calculated based on 1st circle-non intersecting). I can move circle in x direction till it is not intersecting with 1st circle. Similarly 3rd circle, 4th circle. NOw 5th circle needs to moved in y direction till it is non intersecting, (7th,8th,9th in increasing value of x & y value same as that of 5th. Please if anyone has some code , can please share ?
Thanks
|
|
|
|
|
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Use WPF and a DockPanel or a WrapPanel or a combination to load Ellipses into the panel(s): left-to-right, bottom up. In whatever order and direction that works.
Hosted in a top level Grid and with "Stretch" alignment, the "circles" will rearrange as the Window is resized.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi,
if all circles have the same radius R (you did not state this essential information) then it is very simple:
1. for an orthogonal packing, the center will move by 2*R in both directions, so all centers form a simple grid.
2. for the "triangular packing" shown in the reference Dave gave you, the center distances are 2*R in one direction and R*SQRT(3) in the transversal direction.
Proof: the centers form equilateral triangles, so all angles are 60 degrees, and SIN(60)=0.5*SQRT(3) .
Coding this is up to you.
If the radii are different, you have a special (and not an easy) knapsack problem!
modified 11-Apr-19 8:43am.
|
|
|
|
|
I defined a CrawlerTimeoutException that is inherited from task exception, when I throw it in my code,I can't catch it in the main thread, the code is below:
try
{
Random rand = new Random();
await Task.Delay(rand.Next(300, 1000));
var webcontent = await task.Crawl().Timeout(timeout);
}
catch (CrawlerTimeoutException)
{
}
catch (Exception exp)
{
}
I threw the
CrawlerTimeoutException in function
task.Crawl().Timeout(timeout);
the code is below:
public static Task<T> Timeout<T>(this Task<T> task, int millisecondsTimeout)
{
return Task.Factory.StartNew(() =>
{
bool succ = task.Wait(millisecondsTimeout);
if (succ)
return task.Result;
else
throw new CrawlerTimeoutException("Task timeout");
});
}
when it times out, it will throw a exception, but the program will crash because it says: there is a exception that user-unhandled.
I don't know the reason, because I catch it in the main thread twice, but still don't catch it.
if you know the reason, please tell me!
thanks so much!
modified 10-Apr-19 0:04am.
|
|
|
|
|
I just replaced the Task.Factory.StartNew() by Task.run() in Timeout function following this, but it didn't work for my program.
|
|
|
|
|
THreads get complicated, but what it boils down to is that each thread has its own "execution space" which are completely separate: an exception thrown in ThreadA will not be caught in the main thread because they are totally separate. Think about it: the main thread has a totally separate stack to ThreadA so which try...catch block should catch the ThreadA exception?
YOu can do it - the simplest solution is to use a BackgroundWorker which can catch teh error and "pass it on up" to the calling thread:
private void FrmMain_Shown(object sender, EventArgs e)
{
BackgroundWorker work = new BackgroundWorker();
work.DoWork += Work_DoWork;
work.RunWorkerCompleted += Work_RunWorkerCompleted;
work.RunWorkerAsync();
}
private void Work_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Exception ex = e.Error;
if (ex != null) Console.WriteLine(ex.Message);
}
private void Work_DoWork(object sender, DoWorkEventArgs e)
{
throw new NotImplementedException();
}
But there are also ways using asynchronous delegates and the Task Parallel Library, but I haven't needed to use those yet.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Yeah, exceptions thrown in an asynchronous context do not trigger exceptions in a synchronous one (I mean, how could it?)
So, first off, the "built-in" mechanism to do what you're trying to do here is to define a CancellationTokenSource with a timeout and pass that token to your task. You don't need to reinvent the wheel here.
Secondly, there are 2 contexts that you need to consider when handling exceptions in tasks. The first is a try-catch block as part of the task itself for block-level handling, and the second is an external handler for logging or any appropriate module-level responses. The block-level is the basic try-catch we know and love; the external looks sort of like this:
class Program
{
static void Main(string[] args)
{
Task.Run(() =>{throw new NotImplementedException();})
.ContinueWith(task => {
if(task.IsFaulted)
{
Console.WriteLine($"Exception thrown: {task.Exception?.Message}");
}
else
{
Console.WriteLine("You shouldn't see this"));
}
});
var k = Console.ReadLine();
}
}
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
One simple way to fix your method would be:
public static async Task<T> Timeout<T>(this Task<T> task, int millisecondsTimeout)
{
Task timeoutTask = Task.Delay(millisecondsTimeout);
Task completedTask = await Task.WhenAny(task, timeoutTask).ConfigureAwait(false);
if (completedTask == timeoutTask) throw new TimeoutException("Task timeout");
return await task.ConfigureAwait(false);
}
Alternatively, as Nathan suggested, you can use a CancellationTokenSource to cooperatively cancel your task when the timeout expires:
Cancel Async Tasks after a Period of Time (C#) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
When I am Trying to save current list of data into database, I need to get already existing data from database, and need to compare with current list of data.
I have two lists one is PreviousList(existing data from DB) and other is CurrentList(Modified data)
public class SoftClose
{
public int ID = -1;
public int AID = -1;
public int WFID = -1;
public string PREFIX;
public DateTime SCDATE;
public string STATUS;
}
PreviousList
------------
ID Status AID WFID PREFIX SCDATE
1 NO_CHANGE 19 388 D1 01/28/2019
2 NO_CHANGE 20 388 D2 02/25/2019
3 NO_CHANGE 21 388 D3 03/30/2019
CurrentList
-----------
ID Status AID WFID PREFIX SCDATE
1 NO_CHANGE 19 388 D2 01/28/2019
2 NO_CHANGE 20 388 D2 02/25/2019
3 NO_CHANGE 21 388 D3 03/30/2019
4 NO_CHANGE 22 388 D4 04/09/2019
In CurrentList I modified Prefix to D2 where ID=1 and added new row(Id=4)...
My req is
When I am trying to save CurrentList to Db,
If there is any new Prefix in CurrentList that is not there in PreviousList I need to insert that new row and need to change Status to ADD for that row.
I changed Prefix to D2 where Id = 1 in CurrentList. D1 is there is DB and but not in CurrentList so i need to delete it. So i need to change the status to DELETE for that record. I should not insert D2 record where id=1 becuase D2 is already there. If I changed to D5 where Id = 1 then I need to insert it because D5 is not there in DB So i need to change the status to UPDATE.
How to do this? What is the best approach to compare lists
modified 9-Apr-19 22:26pm.
|
|
|
|
|
Sounds like you're using the "master" (file) as some sort of suspense / transaction file ... at the same time.
I think you'd be better off with a separate "transaction" (file) for the "updates, deletes, etc." and a "master" update process ('cuz I'm not familiar with your current CRUD "pattern").
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
|
var list1 = new List<ItemOne>
{
new ItemOne {IDItem = 1, OneProperty = "1"},
new ItemOne {IDItem = 2, OneProperty = null},
new ItemOne {IDItem = 3, OneProperty = "3"},
new ItemOne {IDItem = 4, OneProperty = "4"}
};
var list2 = new List<ItemTwo>
{
new ItemTwo {IDItem = 2, TwoProperty = "2"},
new ItemTwo {IDItem = 3, TwoProperty = "3"},
};
var query = list1.Join(list2, l1 => l1.IDItem, l2 => l2.IDItem, (l1, l2) =>
{
l1.OneProperty = l2.TwoProperty;
return l1;
});
see the above code where two list join and updating first list's one property called OneProperty by second list property called TwoProperty
how to do the same with LINQ normal syntax ? like below onevar data = (from a in list1
join b in list2
on a.IDItem equals b.IDItem into c
from d in c.DefaultIfEmpty()
select new
{
a.OneProperty=(d==null ? string.Empty : d.TwoProperty)
}).ToList();
in the above code i have not used JOIN function rather use join keyword. now tell how to customize my above code to update one property value of list1 by another property value from list2.
please share code or customize my code to work. thanks
|
|
|
|
|
Mou_kol wrote: how to do the same with LINQ normal syntax ? I might get back to this question when very bored, but it is a bad idea to "improve" working code. There's also not much added value in it that I can see.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
suppose i have List1, List2 & List3
now i want to perform left join between List1 & List2 and equi join between List1 & List3 at same place. how to achieve it....if possible please include a sample code.
this kind of join i am looking for
var list1 = new []{
new { CountryID = 12, CountryData = "Has good gras", regionUID = 4567 },
new { CountryID = 12, CountryData = "nice weather", regionUID = 6789 },
new { CountryID = 16, CountryData = "stormy weather", regionUID = 1234 }};
var list2 = new []{
new { CountryID = 12, CountryName = "green hill"},
new { CountryID = 16, CountryName = "stormy mountain"}
};
var list3 = new []{
new {regionUID = 4567, regionName = "above 1000feet"},
new {regionUID = 6789, regionName = "on the ground"},
new {regionUID = 1234, regionName = "on the hill"}
};
var result = from m1 in list1
join m2 in list2 on m1.CountryID equals m2.CountryID
select new { m2.CountryName, m1.CountryData, m1.regionUID } into intermediate
join m3 in list3 on intermediate.regionUID equals m3.regionUID
select new { intermediate.CountryName, intermediate.CountryData, m3.regionName};
but the above code does not suit for my scenario. so please share a sample code where left join between List1 & List2 and equi join between List1 & List3 at same place.
thanks
|
|
|
|
|
They want to change the connection method of a program I write,
this extra request
Clients should connect to the application server, but the connection to the database should be done through the Windows Authentication method over a Windows Service created on the Application server.
what can i do
|
|
|
|
|
As we have no idea what your code currently does, how it works, what its architecture is or even how it's distributed, we aren't going to be able to advise you on how to do this. For instance, does this service already exist or is this something you're going to have to write? What is the purpose of the service? Does it retrieve information?
This space for rent
|
|
|
|
|
SQL Server already allows remote connections over TCP/IP, with authentication, out of the box.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
It's ok,
but i dont understand
Can a service that provides a Sql connection and then return connection , be written
|
|
|
|
|
You don't return the connection. It's only ever used by the data layer.
|
|
|
|
|
You can write a service that executes SQL, but you cannot export your connection, and act as if you are Sql Server.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
And what do you mean by "application server"? What is this and what does it do?
|
|
|
|
|