Why is thermal energy not a state variable? It is written on Wikipedia: (https://en.wikipedia.org/wiki/Thermal_energy)
The thermal energy of a system scales with its size and is therefore an extensive property. It is not a state function of the system unless the system has been constructed so that all changes in internal energy are due to changes in thermal energy, as a result of heat transfer (not work). Otherwise thermal energy is dependent on the way or method by which the system attained its temperature.
My question is: Why thermal energy is dependent on the way or method by which the system attained its temperature? You only need to give me an example proving that. Thanks in advance.
 A: An example you asked for :
Consider a system of an ideal gas where volume of the gas is constant (call it system A) and one where the pressure is constant (System B). Because the internal energy of the system is a state variable, same change in temperature would cause same change in internal energy. Now, $$ \Delta U = Q + W$$
In A volume is constant so W=0 and hence Thermal energy $Q$ is equal to $\Delta U$. But in B the gas will expand, doing some work (say $-W$) and hence for the same change in $U$ we need to supply more thermal energy, equal to $\Delta U +W$.
A: Thermal energy is not a state variable because work can also contribute to thermal energy, e.g. through friction. Work can also contribute to other internal degrees of freedom. In general, work contributes to the total energy 
$$U = U_{\rm thermal} + U_{\rm non-thermal}.$$
Since work should be considered as contributing only to the total internal energy $U$, so should the heat $Q$, and therefore 
$$Q+W = \Delta U.$$
I think $Q$ could even contribute to non-thermal degrees of freedom if accompanied by an additional increase in entropy. I'm not 100% sure about this last statement.
