threads and objects


Hey dear Friends...



I'm developing a code for an assignment given that find a solution for a modified Dining philosophers problem.. For that problem I had to create four classes. `Philosopher` , `chopStick` , `samllBowl` and `bigBowl` .. I implemented the class `philosopher` as Runnable.. And the problem is this.. As far as I know I have to write whatever I need to do with the thread within the `run` method.. I want to call methods of other classes which I created.. but I haven't created any objects of those class in the philosophers class.. all objects are created within the main class, main method... so how can I access the getStick() method defined within the chopStick class....? thank you in advance..
> how can I access the getStick() method defined within the chopStick class
> 
> 


To access any part of an instance of a class, you need a reference to that instance.  

Some where you create an instance:  

AnObject aRef= new AnObject(); // create an instance and set reference to that object



then you need to make that reference available where you want to call its methods:  

aRef.aMethod(); // call a method in the AnObject class
I have the same problem and added this to the DbContext:



```
private void PrintStackTrace()
{
  var st = new StackTrace();
  foreach (var sf in st.GetFrames())
    Console.WriteLine($"{sf.GetMethod().DeclaringType.Assembly.GetName().Name} {sf.GetMethod().DeclaringType.Name} {sf.GetMethod().Name}");
}

```

and call this function in the contructor and Dispose of the DbContext.


It seems to be a problem, if the DbContext is added with scoped lifetime to the dependency injection. I filed an issue for that.


<https://github.com/aspnet/EntityFrameworkCore/issues/10693> The object you are linking with was built with the option to use the static run-time libraries, whereas your DLL was (properly) built to use the DLL libraries. When you mix these you'll get complaints such as this.


Since Fortran objects don't care which library set is used (this is not true of C/C++), one option could be to set the Linker>Input property "Ignore all default libraries" (/NODEFAULTLIB) in your DLL project. You will then need to name the required libraries under Additional Dependencies. (You can use the dumpbin command on your DLL's object to see a list.)


If you can rebuild the external object, do so with the Fortran > Libraries > Disable default library search rules property set to Yes. Then you should be able to link it in without further issue.




[View solution in original post](/t5/Intel-Fortran-Compiler/Error-linking-to-external-obj-file/m-p/1144075#M138021) I suggest to use PostThreadMessage instead of SendMessage, check [PostThreadMessage Demystified](http://www.codeproject.com/Articles/225755/PostThreadMessage-Demystified)[[^](http://www.codeproject.com/Articles/225755/PostThreadMessage-Demystified "New Window")] for reasons. For Documentation see <http://msdn.microsoft.com/en-us/library/windows/desktop/ms644946%28v=vs.85%29.aspx>[[^](http://msdn.microsoft.com/en-us/library/windows/desktop/ms644946%28v=vs.85%29.aspx "New Window")]  

  

And by the way if you want to invoke a function of your dialog class from your thread, then you need to send the "this"(present dialog object reference) as a parameter to the thread procedure. Are you sure you are doing this? Because in the code you are casting you lParam into an int which baffles me. When you call your threadproc you need to send "this" as "lParam".  

With SendMessage the code would look something like :   


```
 void ThreadProc(LPVOID lParam)
{
   CCurrentDialog* pDlg = (CCurrentDialog*)lParam;
   SendMessage(pDlg->m\_hWnd,ON\_CBN\_SELCHANGE,NULL,NULL);
}
```
  

  

You can use [PostMessage](http://msdn.microsoft.com/en-us/library/windows/desktop/ms644944%28v=vs.85%29.aspx)[[^](http://msdn.microsoft.com/en-us/library/windows/desktop/ms644944%28v=vs.85%29.aspx "New Window")] also. ok. i have solved it. the problem was a misunderstanding of what freecodecamp wanted me to do. first they stated:

you can make a get request to /api/exercise/log with a parameter of userid=\_id to retrieve “a full exercise of " any user”

so i thought they meant all the exercises of users in the … you are mixing up "for all iterators i" with "for some specific kind of iterator i".

what if i decide to call foo<std::vec::intoiter<string>>? then you have a function that takes an intoiter<string>, but you tried to call it with an skip<intoiter<string>>, which is a different type. hence a type mi… Hi Uwe, You can make inside/outside strokes on non-closed paths using custom width profiles. Use thhe width tool (Shift+W) to make a stroke like this (hold alt to edit only one side of the stroke at a time): Then save it as a profile (bottom of the stroke panel). After that I think your path should be easy to make. hello dror, - - you can inherit the ribbontab base class and add some custom elements to the children collection, - i have prepared a very small example, it should get you started: - - - using system; -     using system.drawing; -     using system.windows.forms; -     using telerik.wincontrols; -     using telerik.wincontrols.ui; -   -     public partial class radribbonform1 : telerik.wincontrols.ui.radribbonform -     { -         public radribbonform1() -         { -             initializecomponent(); -         } -   -         protected override void onload(eventargs e) -         { -             base.onload(e); -   -             var tabitem1 = new customribbontab(manage); -             var tabitem2 = new customribbontab(remove); -             radribbonbar1.commandtabs.addrange(new customribbontab[] { tabitem1, tabitem2 }); -         } -     } -   -     public class customribbontab : ribbontab -     { -         private radbuttonelement radbuttonelement; -   -         protected override type themeeffectivetype -         { -             get -             { -                 return typeof(tabitem); -             } -         } -   -         private timer focustimer; -   -         public customribbontab() -             : base() -         { -             createtimer(); -         } -   -         public customribbontab(string text) -             : base(text) -         { -             createtimer(); -         } -   -         private void createtimer() -         { -             this.focustimer = new timer { interval = 500 }; -             this.focustimer.tick += delegate -                 { -                     this.radbuttonelement.visibility = elementvisibility.collapsed; -                 }; -         } -   -         protected override void createchildelements() -         { -             base.createchildelements(); -   -             radbuttonelement = new radbuttonelement(x); -             radbuttonelement.size = new size(10, 10); -             radbuttonelement.minsize = new size(10, 10); -             radbuttonelement.maxsize = new size(10, 10); -             radbuttonelement.click += new eventhandler(radbuttonelement\_click); -             radbuttonelement.mouseenter += new eventhandler(radbuttonelement\_mouseenter); -             radbuttonelement.mouseleave += new eventhandler(radbuttonelement\_mouseleave); -             radbuttonelement.borderelement.visibility = elementvisibility.collapsed; -             radbuttonelement.visibility = elementvisibility.collapsed; -             this.children.add(radbuttonelement); -         } -   -         void radbuttonelement\_mouseleave(object sender, eventargs e) -         { -             this.onmouseleave(e); -         } -   -         void radbuttonelement\_mouseenter(object sender, eventargs e) -         { -             this.onmouseenter(e); -         } -   -         void radbuttonelement\_click(object sender, eventargs e) -         { -             ((telerik.wincontrols.ui.radtabstripelement)(this.parenttabstrip)).items.remove(this); -         } -   -         protected override void onmouseenter(eventargs e) -         { -             base.onmouseenter(e); -             focustimer.stop(); -             radbuttonelement.visibility = elementvisibility.visible; -         } -   -         protected override void onmouseleave(eventargs e) -         { -             base.onmouseleave(e); -             focustimer.start(); -         } -   -         protected override sizef arrangeoverride(sizef finalsize) -         { -             finalsize = new sizef(finalsize.width + this.children[3].desiredsize.width, finalsize.height); -             base.arrangeoverride(finalsize); -   -             this.children[3].arrange(new rectanglef( - (int)(finalsize.width - 1.7 * this.children[3].size.width), (finalsize.height / 2) - (this.children[3].desiredsize.height / 2 + 1), finalsize.width, this.children[3].desiredsize.height)); -   -             return finalsize; -         } -   -         protected override void disposemanagedresources() -         { -             radbuttonelement.click -= new eventhandler(radbuttonelement\_click); -             radbuttonelement.mouseenter -= new eventhandler(radbuttonelement\_mouseenter); -             radbuttonelement.mouseleave -= new eventhandler(radbuttonelement\_mouseleave); -   -             base.disposemanagedresources(); -         } -     } - - - please see the attached image if this is what you wanted. - - hope this helps, if you have any other questions or comments, please let me know, - - best regards, - emanuel varga The problem is that your pair's closure must return two different types of objects: int if you ask for "con", and the next closure on the line if you ask for "crd".


Here's one possible implementation:


Use a speaker so you can come back.



```
public static Func<string, dynamic> Pair(int x, Func<string, dynamic> y)
{
    Func<string, dynamic> pair =
           (a) =>
           {
               if (a == "con") return x;
               if (a == "crd") return y;
               throw new Exception();
           };

    return pair;
}

public static void Print(Func<string, dynamic> pair)
{
    while (true)
    {
        var next = pair("crd");
        Console.WriteLine((next == null ? "-":"+") +"> " + pair("con"));
        if (next != null)
        {
            Console.WriteLine("|");
            pair = (x) => next(x);
            continue;
        }
        break;
    }
}

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```


  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

Test:



```
var pair = Pair(1,
            Pair(2,
                  Pair(3,
                        Pair(4, null))));

Print(pair);

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

output:



```
+> 1
|
+> 2
|
+> 3
|
-> 4

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
``` Using [reflection](/questions/tagged/reflection "show questions tagged 'reflection'") and [expression-trees](/questions/tagged/expression-trees "show questions tagged 'expression-trees'") you can provide the parameters and then call `OrderBy` function, Instead of returning `Expression<Func<Task, T>>` and then calling `OrderBy`.


Note that `OrderBy` is an extension method and has implemented in both `System.Linq.Enumarable` and `System.Linq.Queryable` classes. The first one is for [linq-to-objects](/questions/tagged/linq-to-objects "show questions tagged 'linq-to-objects'") and the latter is for [linq-to-entities](/questions/tagged/linq-to-entities "show questions tagged 'linq-to-entities'"). [entity-framework](/questions/tagged/entity-framework "show questions tagged 'entity-framework'") needs the expression tree of the query in order to translate it to SQL commands. So we use the `Queryable` implementation.


It can be done by an extension method(explanations added as comments):



```
public static IOrderedQueryable<TSource> OrderBy<TSource>(
       this IQueryable<TSource> query, string propertyName)
{
    var entityType = typeof(TSource);

    //Create x=>x.PropName
    var propertyInfo = entityType.GetProperty(propertyName);
    ParameterExpression arg = Expression.Parameter(entityType, "x");
    MemberExpression property = Expression.Property(arg, propertyName);
    var selector = Expression.Lambda(property, new ParameterExpression[] { arg });

    //Get System.Linq.Queryable.OrderBy() method.
    var enumarableType = typeof(System.Linq.Queryable);
    var method = enumarableType.GetMethods()
         .Where(m => m.Name == "OrderBy" && m.IsGenericMethodDefinition)
         .Where(m =>
         {
            var parameters = m.GetParameters().ToList();
            //Put more restriction here to ensure selecting the right overload                
            return parameters.Count == 2;//overload that has 2 parameters
         }).Single();
    //The linq's OrderBy<TSource, TKey> has two generic types, which provided here
    MethodInfo genericMethod = method
         .MakeGenericMethod(entityType, propertyInfo.PropertyType);

    /*Call query.OrderBy(selector), with query and selector: x=> x.PropName
      Note that we pass the selector as Expression to the method and we don't compile it.
      By doing so EF can extract "order by" columns and generate SQL for it.*/
    var newQuery = (IOrderedQueryable<TSource>)genericMethod
         .Invoke(genericMethod, new object[] { query, selector });
    return newQuery;
}

```

Now you can call this overload of `OrderBy` like any other overload of it.  

For example:



```
var cheapestItems = _context.Items.OrderBy("Money").Take(10).ToList();

```

Which translates to:



```
SELECT TOP (10)  {coulmn names} FROM  [dbo].[Items] AS [Extent1] 
       ORDER BY [Extent1].[Money] ASC

```

This approach can be used to define all overloads of `OrderBy` and `OrderByDescending` methods to have `string` property selector. Hello, [@Trulines87](/c/user/viewprofilepage/user-id/733134).


Welcome to Shopify Community. My name is Olivia and I work here.


Thanks for posting your question, I can definitely help you out with this today. There are a couple of different ways we can tackle this, so let's dive right in to your options.


**A. Use your design time.**


Each store on a paid plan, using a Shopify developed theme, is allotted a full 60 minutes of design time for minor changes. While it's best to check with our [Support Team](https://bit.ly/2XDcBxK) on what changes we can, and can't accommodate, your request is definitely one we could look after. If you have a specific idea of what you would like your footer to look like let me know and I can connect you with our Theme team. Just be as detailed as possible with your request, maybe even including examples, to help us make the right changes. Make sure to check out our [design policy](https://bit.ly/31wVsHb) to read more about support for Shopify themes.


***OR***


**B. Add text to your footer code.**


If you're comfortable with making code changes you can save your design time for something else. It will be helpful to have basic knowledge of HTML and CSS to help you customize the style and layout of added text, but I can point you towards making these changes on your own. Head to **Shopify Admin > Online Store > Themes > Narrative > Actions > Edit Code** and scroll down to */sections* to find the file **footer.liquid**.


Narrow down this piece of code on line 32:


 



```
{% when 'menu' %}

```

 


Now, insert your text after that line. Make sure to add <p> before your text, and </p> at the end of your text to close the code. Here's an example:


 



```
            {% when 'menu' %}
            <p> Add your contact info </p>
              {%- assign link_list = block.settings.link_list -%}
```

 


This is how it would appear on your website:


![08-26-ndww6-2kmgo](/c/image/serverpage/image-id/57763i1C21A51AE550DEAA/image-size/large?v=1.0&px=999 "08-26-ndww6-2kmgo")


That's it! You can take it a step further and make it even easier for your customers to contact you by adding a direct email link. Simple code like this would work: 


 



```
<a href="mailto:yourmail@domain.com">Insert your business email address</a>
```

 


Same thing for a "click-able" phone number to help customers easily phone you:


 



```
<a href="tel:18001112233">1-800-111-2233</a>
```

 


And we're done! Don't forget to replace the email address and phone number in those codes with your own information.


That should work, but let me know if any other questions come up that I can help with.


Warm regards,



**Olivia | Social Care @ Shopify**  
 - Was my reply helpful? Click **Like** to let me know!   
 - Was your question answered? Mark it as an **Accepted Solution** - To learn more visit the [Shopify Help Center](https://help.shopify.com/) or the [Shopify Blog](https://www.shopify.ca/blog)